Chapter II: Variables and simple data types Chapter II: Variables and simple data types

Chapter II: Variables and simple data types

Chapter II: Variables and simple data types
 
 
 
2.2.1 variable naming and use Hello_python.py
First, the rule of variables
1) Variable names can only contain letters, numbers, and underscores child
2) Variable names may begin with a letter or underscore, but can not begin with the number of child
    Example: correct variable names: message_1 Error: 1_message
 
3) Variable names can not contain spaces, but you can use underscores to separate words which
    Example: correct variable names: greeting_message Error: greeting message
 
4) Do not Python function names and keywords used as variable names that do not use the Python reserved for special words for
    例:print    for  if....
 
5) variable names to be simple and clear and descriptive
    Example: name length_of_persons_names better than better than n student_name better than s_n name_length
6) caution lowercase l and uppercase letters O, as they may chant the wrong people as the number of sub 1 and 0
 
 
2.3 strings name.py first_name.py
1, the variable name .title () method
          title () displays each word in uppercase first letter of the way, is about the first letter of each word to uppercase
 
2, variable names .upper () method
    upper () all the contents of the string to uppercase
 
3, variable names .lower () method
    lower () contents all lowercase string
 
 
 
2.3.3 tab or newline to add blank languages.py
1, include tabs in the string of characters may be used in combination \ t
    例:print("\tPython")
 
2, add a line break in the string of characters may be used in combination \ n
    例:print("Languages:\nPython\nC++\nJavaScript")
 
3, may also comprise tabs and line breaks while the same string
    例:print("Languages:\n\tPython\n\tC++\n\tJavaScript")
 
 
2.3.4 delete blank languages.py
 
1) rstrip () method: the end of the string can eliminate extra blank
    
例:>>> favorite_language=" python "
            >>> favorite_language.rstrip
             " python"
 
 
2) lstrip () method: beginning of the string can eliminate extra blank
   
例:>>> favorite_language=" python "
        >>> favorite_language.lstrip
              "python "
 
 
3) strip () method: the ends can be simultaneously removed empty string
   
例:>>> favorite_language=" python "
            >>> favorite_language.strip
             "python"
 
 
Use Geany editor to write statements for exercise 1-4.py
 
name="     albert einstein      "
 name_strip=name.strip()
  print (name_strip.title ()) Note: Excluding the name and the first letter capitalized display space
 
 
2.4 Kazuko
2.4.1 birthday.py integer number of sub-practice -1.py
 
1) in python, to integer execution may be plus (+) decrease (-), multiply (*) except (/)
2) in the terminal, Python be used by two numerals exponentiation
    例:>>> 3 ** 2       >>> 3 ** 3       >>> 10 ** 6
           9                27              1000000
 
 
2.5 Notes
In Python # symbol is a comment
 
2.6 Python Zen
>>> import this input terminal
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0
0
<< psalm: Chapter Four: Action List
>> Next: Old Boys Day7 jobs: elective system
@. Posted 2017-12-07 12:45   empty cicada Xiangxi s reading ( 75 ) Comments ( 0 ) edit collections
Chapter II: Variables and simple data types
 
 
 
2.2.1 variable naming and use Hello_python.py
First, the rule of variables
1) Variable names can only contain letters, numbers, and underscores child
2) Variable names may begin with a letter or underscore, but can not begin with the number of child
    Example: correct variable names: message_1 Error: 1_message
 
3) Variable names can not contain spaces, but you can use underscores to separate words which
    Example: correct variable names: greeting_message Error: greeting message
 
4) Do not Python function names and keywords used as variable names that do not use the Python reserved for special words for
    例:print    for  if....
 
5) variable names to be simple and clear and descriptive
    Example: name length_of_persons_names better than better than n student_name better than s_n name_length
6) caution lowercase l and uppercase letters O, as they may chant the wrong people as the number of sub 1 and 0
 
 
2.3 strings name.py first_name.py
1, the variable name .title () method
          title () displays each word in uppercase first letter of the way, is about the first letter of each word to uppercase
 
2, variable names .upper () method
    upper () all the contents of the string to uppercase
 
3, variable names .lower () method
    lower () contents all lowercase string
 
 
 
2.3.3 tab or newline to add blank languages.py
1, include tabs in the string of characters may be used in combination \ t
    例:print("\tPython")
 
2, add a line break in the string of characters may be used in combination \ n
    例:print("Languages:\nPython\nC++\nJavaScript")
 
3, may also comprise tabs and line breaks while the same string
    例:print("Languages:\n\tPython\n\tC++\n\tJavaScript")
 
 
2.3.4 delete blank languages.py
 
1) rstrip () method: the end of the string can eliminate extra blank
    
例:>>> favorite_language=" python "
            >>> favorite_language.rstrip
             " python"
 
 
2) lstrip () method: beginning of the string can eliminate extra blank
   
例:>>> favorite_language=" python "
        >>> favorite_language.lstrip
              "python "
 
 
3) strip () method: the ends can be simultaneously removed empty string
   
例:>>> favorite_language=" python "
            >>> favorite_language.strip
             "python"
 
 
Use Geany editor to write statements for exercise 1-4.py
 
name="     albert einstein      "
 name_strip=name.strip()
  print (name_strip.title ()) Note: Excluding the name and the first letter capitalized display space
 
 
2.4 Kazuko
2.4.1 birthday.py integer number of sub-practice -1.py
 
1) in python, to integer execution may be plus (+) decrease (-), multiply (*) except (/)
2) in the terminal, Python be used by two numerals exponentiation
    例:>>> 3 ** 2       >>> 3 ** 3       >>> 10 ** 6
           9                27              1000000
 
 
2.5 Notes
In Python # symbol is a comment
 
2.6 Python Zen
>>> import this input terminal
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Guess you like

Origin www.cnblogs.com/gaodi2345/p/11412875.html