Course Content
Data Types in Python
Data Types in Python
Print Your String
Good to see you again!
It's time to talk about a data type that has become an inseparable part of coding: strings. Strings are a way to input your everyday words into a Python program. Python recognizes specific words like "print," "if," and others as special, but for your own words, you need to enclose them in single quotes ('word'
) or double quotes ("word"
) – you can use either of these two ways.
Let's look at the example:
string1 = "cat" string2 = 'cat' print("The first output is", string1) print("The second output is", string2)
There's another way to define strings that's not used as often, and it involves using triple quotes:
string = """ Hello, I am learning Python to receive the job of my dream. By the way, even one task a day helps me inch my way towards success! I am in control of my life, and I improve it every day! """ print(string)
This type of definition can be used when our string consists of several lines (we will receive an error otherwise):
string = 'Hello, I am learning Python to get the job of my dreams. By the way, even one task a day helps me inch my way towards success! I am in control of my life, and I improve it every day!'
Swipe to show code editor
- Tell me about the weather in your city. Assign
bad
to the variablestring1
if the weather outside is bad; otherwise, assigngood
. - Tell me about your mood today! Assign
could be better
to the variablestring2
if your mood is not okay; otherwise, assigncould not be better
. - Now tell me if your mood depends on the weather. Assign
yes
to the variablestring3
if it depends; otherwise, assignno
.
Thanks for your feedback!
Print Your String
Good to see you again!
It's time to talk about a data type that has become an inseparable part of coding: strings. Strings are a way to input your everyday words into a Python program. Python recognizes specific words like "print," "if," and others as special, but for your own words, you need to enclose them in single quotes ('word'
) or double quotes ("word"
) – you can use either of these two ways.
Let's look at the example:
string1 = "cat" string2 = 'cat' print("The first output is", string1) print("The second output is", string2)
There's another way to define strings that's not used as often, and it involves using triple quotes:
string = """ Hello, I am learning Python to receive the job of my dream. By the way, even one task a day helps me inch my way towards success! I am in control of my life, and I improve it every day! """ print(string)
This type of definition can be used when our string consists of several lines (we will receive an error otherwise):
string = 'Hello, I am learning Python to get the job of my dreams. By the way, even one task a day helps me inch my way towards success! I am in control of my life, and I improve it every day!'
Swipe to show code editor
- Tell me about the weather in your city. Assign
bad
to the variablestring1
if the weather outside is bad; otherwise, assigngood
. - Tell me about your mood today! Assign
could be better
to the variablestring2
if your mood is not okay; otherwise, assigncould not be better
. - Now tell me if your mood depends on the weather. Assign
yes
to the variablestring3
if it depends; otherwise, assignno
.
Thanks for your feedback!