Dec 27, 2021

Python #2

Common Command

quit ( )

String

# this for short string
name = "4edcuation"
print (name)

# for long string using 3 quote
name = """ 
4education
4edt
4e+
"""
# Concatenation of string
room = "room number" + str(10) 

# Escape Sequence

say_01 = "Hello it's me"
say_02 = "Hello it's \"me\" bro"
say_03 = "\t Hello it's \"me\ " bro"
say_04 = "\t Hello \n it's \"me\" bro"

\t for tab, and \n = enter or new line 

# Formatted string

name = '4edt'
age = 33
print ('hi '+ name + '. You are ' + str(age) + ' years old')
print (f'hi {name}. You are {age} years old')
print ('hi {}. You are {} years old'. format(name, age))


Try and Except

try:
x1 = float(input("Please enter the number: "))
except:
print("Error input number1")
>>
Please enter the number: 1
>>
Please enter the number: a
Error input number1

Text Format

var1 = "My NaMe"
print(var1.lower())
print(var1.upper())
print(var1.capitalize())
print(var1.title())
>>
my name
MY NAME
My name
My Name