1, the name of the variable
Same as C language
2. String
is a series of characters. In Python , a string is enclosed in quotation marks, where the quotation marks can be single or double quotes
2.1 using methods to modify the case of a string
One of the simplest things you can do with strings is to modify the case of words in them. Take a look at the code below and try to determine its role
(That is, call a statement that resembles a function, in the form of a variable name followed by a dot, plus the name of the method)
" Ada Lovelace " Print (Name.title ())
The last piece of code means to use the title () method to change the first letter of each word of the string stored in the name variable to case.
So the question is, what is the method?
method is What Python can do with data
There are all sorts of ways.
For example, change all to uppercase or lowercase
Name = "Ada Lovelace" Print (Name.upper ()) #全部改为大写print (Name.lower ()) #全部改为小写
2.3.2 Merging (stitching) strings
You can use the plus sign.
Example:
" Ada " "Lovelace " "" + last_name Print
Both the variable name and the quotation mark can be used in combination
Python can find extra whitespace at the beginning and end of a string. To ensure that there is no whitespace at the end of the string, use Method Rstrip () .
3. Digital
3.1 Integers
Python uses two multiplication sign to represent a exponentiation operation
3.2 Floating point
3.2.1 using function str () to avoid type errors
That is, the C language coercion type conversion, because sometimes the computer does not know that you write the variable is the integer type or as a character.
Usage:
Age ="" "Rd birthday! " Print (message)
3. Introduction to the list A list consists of a series of elements arranged in a particular order. You can create a list of all the letters, numbers 0~9, or names of all family members in the alphabet, or you can add anything to the list, where the elements can have no relationship. Given that a list usually contains multiple elements, it is a good idea to give the list a name that represents a complex number (such as letters , digits, or names ).
in Python , square brackets ([] ) to represent the list, separating the elements with commas. Here is a simple example of a list that contains several bikes:
Bicycles = ['trek''Cannondale'redline ' ' Specialized ' ]print(bicycles)
Python Learning notes-variables and simple data types