Python Programming with Corey Schafer_Notes_2
Python Programming with Corey Schafer_Notes_2
Lecture 2 - Strings
• Setting variable
message = ‘Hello World’
print(message)
→ Hello World
• Single quote
message = ‘Bobby’s World’
print(message)
→ error
It is because of two ’ ’
Solution 1 of error
message = ‘Bobby\’s World’
print(message)
→ Bobby’s World
Solution 2 of error
message = “Bobby’s World”
print(message)
→ Bobby’s World
• Multi-line string
message = “““Bobby’s World was a
good cartoon”””
print(message)
→ Bobby’s World was a
good cartoon
greeting = ‘Hello’
name = ‘Michael’
message = greeting + ‘, ’ + name + ‘. Welcome!’
print(message)
→ Hello, Michael. Welcome!
greeting = ‘Hello’
name = ‘Michael’
message = f‘{greeting}, {name.upper()}. Welcome!’
print(message)
→ Hello, MICHAEL. Welcome!
For uppercase name
• To know about all the attributes and methods available with a variable
name = ‘Michael’
print(dir(name))