Catalog
1. Variable naming and use
2. character string
3. add to & Delete blanks
5.str()
1.1 Variable names can only be Contain letters 、 Numbers and underscores . Variable names can start with letters or underscores , But don't start with numbers .
eg: You can name the variable qqq_0, But it can't be named 0_qqq
1.2 Variable names cannot contain spaces , But you can use an underline to separate the words .
eg: Variable name xxx_xxx feasible , But the variable name xxx xxx Error will be raised .
2.1 character string : A string is a series of characters , You can use single quotes / Double quotation marks indicate
2.2 Change the case of words title(), Here's the picture , The running result is Skkd Kkd
name = "skkd kkd"
print("name.title()")
2.3 Change the case of the whole word upper()、lower(), Here's the picture , The running result is SKKD KKD and skkd kkd
name = "skkd kkd"
print("name.upper()")
print("name.lower()")
2.4 Merge strings : Use the plus sign (+ ) To merge strings , Here's the picture , The running result is It is a dog
A = "It is"
B = "a dog"
what = A + " " + B
print(what)
Add blanks :
1.4.1 Line breaks use \n
1.4.2 Use tabs \t
#1.5.1 Delete the end blank , Usage method rstrip()
a = ' It is fine '
a.rstrip()
#1.5.2 Eliminate the blank at the beginning , Usage method lstrip()
a = ' It is fine '
a.lstrip()
#1.5.3 Eliminate whitespace at the beginning and end , Usage method strip()
a = ' It is fine '
a.strip()
Avoid typos , Need to use str()
number = 18
message = "I am" + age + "years old!"
print(message)
# Error will be reported at this time , because number yes int type , So will number convert to str type , Change it to :
number = 18
message = "I am" + str(age) + "years old!"
print(message)
The learning content of this article refers to 《Python Programming : From introduction to practice 》