Main Concept: Dealing with strings and print formatting.
Here are a few things that can help you understand the Main Concept for todays lesson:
1. Strings
2. Type Conversions
3. Print Formatting
4. Format Specifiers
By the end you will be able to: Understand how strings are simply sequences of characters, how to do unique things with them, and how to print them in nice ways.
1. Strings
Similar to how we represent whole numbers as ints, or decimal numbers as floats, we can represent words, sentences, and even sometimes numbers, as strings. Below we will show examples of what some strings in Python could look like, what it looks like when you print them out, and how they are different from other data types. Note one thing, all strings are wrapped in either single ‘ or double “ quotes.
2. Type Conversions
It may seem a bit odd that numbers can be represented in so many different ways. Not only do we have different types for whole numbers (int) and decimal numbers (float), but we can even have numbers held in a string data type. Luckily for us, Python allows us to easily change between data types. With the following commands, you can switch from ints/floats to strings and vice versa.
3. Print Formatting
Printing out single variables is nice, but luckily, Python allows us to print things in a more convenient way. We call formatting the way we output things, string/print formatting.
Let’s say we want to greet someone with code. We ask for their name, with an input statement, and then we can print out their name. Here’s a few ways we can do it:
To say hello to whoever is using our program. Let’s imagine someone named “Cindy” answered the question above. we can try a few different methods:
4. Format Specifiers
Using that “f” in a print statement allows us to do many useful things when outputting information from our program. For example, one useful thing we can also do with this format specifier is get it to print out a certain number of digits in a float number.
Last Lessons Content
Main Concept: Making decisions with code.
By the end you will be able to: Know how to make decisions in your code and do different things depending on what the user inputs.
Last Lessons Content
Next Lessons Content
Main Concept: Making decisions with code.
By the end you will be able to: Know how to make decisions in your code and do different things depending on what the user inputs.
Main Concept: Saving multiple elements and manipulating variables
By the end you will be able to: Store a variety of elements inside of one variable, know how to get certain elements out, and how to manipulate strings/lists.