One, string
The magic of single and double quotes in string, different from the Java language, ' I told my friend, ' Python is my favorite language! '
Create a name.py file
1. String case use title (), Upper (), Lower ()
name = "Ada Lovelace"
Print (Name.title ())
Print (Name.upper ())
Print (Name.lower ())
Output: AdaLovelace; AdaLovelace; ada Lovelace ;
# title (): Capitalize the first letter of each word in the string in our Output window (Note: The only way to modify the display is to change the contents of the variable)
#Upper (): Capitalize all words in a string (note: The only way to modify the display is to modify the contents of the variable)
#Lower (): The words in the string are all lowercase (note: Only the way to modify the display, and not modify the contents of the variable)
2, the concatenation of strings
first_name = "Ada"
last_name = "Lovelace"
Full_name = first_name + "" + last_name
#用 + symbol to complete stitching
3. use tabs or newline characters to add white space (definition of blank: include tab \ t, line break \ n)
>>> print ("Python")
Python
>>> print ("\tpython")
Python
>>> print ("Languages:\npython\nc\njavascript")
Languages:
Python
C
Javascript
4. Deletion of whitespace:Rstrip () Remove all whitespace at the end,lstrip () remove all whitespace at the beginning, strip () remove all whitespace at the beginning and end
>>> favorite_language = ' python '
>>> Print (Favorite_language)
' Python '
>>>print (Favorite_language.rstrip ())
' Python '
>>> >print (Favorite_language)
' Python '
# Rstrip () can only modify the temporary display method of the string, cannot permanently modify the contents of the variable, that is, cannot permanently delete the white space inside the string
File "apostrophe.py", line 1
Message = ' One of Python ' s strengths is its diverse community. '
An error occurred in the appeal code:syntaxerror:invalid syntax, which means that an invalid character segment has occurred
Second, integer (int)
in the in Python, a plus (+) minus (-) multiplication (*)is performed on an integer.
Three, floating point (float)
Python is called a number with a decimal point as a floating point
Iv. splicing and conversion between numbers and strings
Age = 23
message = "Happy" + age + "Rd birthday!"
Print (message)
The above code will appear error typeerror:can ' t convert ' int ' object to str implicitly is a type exception error
So we need to convert the data type of age into string data, so it should be written as STR (age) to dismiss the error
Five,import this
Understand Python's programming ideas and programming beautifully
Python Learning path day01--simple data types