Introduction to Python programming foundation

  Python programming from entry to entry basis practice -------

  1, Python variables in

  2, Python capitalized use title () method, all uppercase upper () method, all lowercase lower () method

  3, Python string using the + splicing

  4, Python remove the string space delete trailing spaces of rstrip (), delete the spaces at the beginning of lstrip (), delete the spaces at both ends of the strip ()

  5, Python2 of print and python3 difference:

  6, Python integer arithmetic, by using two numbers represents exponentiation

  7, Python avoid using the wrong type str () function and the other type value into a string

  8, Python comments in

  1, Python variables in

  Variable name: a combination of English case, numbers and underscores, and can not begin with a number

  2, Python capitalized use title () method, all uppercase upper () method, all lowercase lower () method

  >>> name='ce shi python'

  >>> name.title();

  'Ce Shi Python'

  >>> print(name.upper())

  CE SHI PYTHON

  >>> name2="CE SHI PYTHON"

  >>> print (name2.lower())

  ce shi python

  3, Python string using the + splicing

  >>> first_name='ce'

  >>> last_name="shi"

  >>> full_name=first_name + last_name

  >>> print(full_name)

  ceshi

  >>> print("Hello"+" "+full_name+" "+'welcome!')

  Hello ceshi welcome!  Wuxi gynecological where good http://www.xasgfk.cn/

  4, Python remove the string space delete trailing spaces of rstrip (), delete the spaces at the beginning of lstrip (), delete the spaces at both ends of the strip ()

  >>> best_language=" python "

  >>> best_language = best_language.rstrip()

  >>> best_language

  ' python'

  >>> best_language = best_language.lstrip()

  >>> best_language

  'python'

  >>> best_language=" python "

  >>> best_language

  ' python '

  >>> best_language.strip()

  'python'

  5, Python2 of print and python3 difference:

  python2 no need to print the contents of the brackets. python3 is a function of the print, so essential in parentheses; python2 of print also includes some parentheses.

  6, Python integer arithmetic, by using two numbers represents exponentiation

  >>> 3**2 #(=3*3)

  9

  >>> 10**3

  1000

  7, Python avoid using the wrong type str () function and the other type value into a string

  >>> age = 25

  >>> message = "Happy " + str(age) +" Birthday!"

  >>> message

  'Happy 25 Birthday!'

  >>> print(message)

  Happy 25 Birthday!

  8, Python comments in

  Beginning with #, the latter is a comment


Guess you like

Origin blog.51cto.com/14335413/2431287