Linux installation: Compiling and installing the installation package download
Python installation package:
Python-3.5.5.tgz
Tar zxvf python-3.6.4.tgz CD Python-3.6.4
Specifying the installation directory
./configure--prefix=/home/sshuser/python3.6 Make do install
Check version
/home/dxl/python3.5/bin/python3.6–v
Install the three-party library
Cd/home/dxl/python3.6/lib mkdir site-packages CD site-packages/
Third-party libraries are placed in the "Site-packages" folder
/home/dxl/python3.6/bin/python3 setup.py Install
Welcome to Print
Python 2
print "Hello World" Hello world!
Python 3
Print ("Hello world!") Hello world!
Variable
Mesage = "Hello world!"
Print (mesage)
Hello world!
Naming and use of variables
- Variable names can contain only letters, numbers, and underscores. Variable names can start with a letter underline and cannot begin with a number.
- Variable names cannot use spaces, you can use underscores to split words
- Variable name do not use Python keyword and function name as variable name
- Variable names should be short and descriptive. For example: Name and n both represent names, and name is the best.
- Use the lowercase letters "l" and "O" with caution, as the value "1" "0" is apt to be mistaken.
# python写法 gf_of_oldboy = "chen chen" # 驼峰写法 GFoFOldboy = "chen chen" # 常量用全大写 PIE = "Jor Lei"~~
String
There is no difference between single and double quotes in Python
- Modify String case
Name = "Hello world!"
Capitalize the first letter of the word
Print (Name.title ())
Hello world!
Capitalize all letters in a word
Print (Name.upper ())
HELLO world!
Word All Letter Lowercase
Print (Name.lower ())
Hello world!
- string concatenation
Use "+" to merge strings, do not use "+", + open up multiple blocks of memory, inefficient
Namea = "Hello"
NAMEB = "World"
Full_name = Namea + "" + Nameb + "!"
Results Demo
Print ("===>>%s"%full_name)
===>>hello world!
info = "------Info of%s------name:%s age:%s jor:%s salary:%s"% (name,name,age,job,salary)
%s:字符串%d:数字%f:浮点(小数)
- Use tabs and line breaks to add whitespace
制表符“\t”,换行符“\n”
Print ("\npython")
Python
Print ("Languages:\npython\nc\njava")
Languages
Python
C
Java
Print ("Languages:\n\tpython\n\tc\n\tjava")
Languages
Python
C
Java
- Delete spaces in a string
Name = "Hello world!"
Remove trailing spaces
Print (Name.rstrip ())
Hello world!
Remove Head space
Print (Name.lstrip ())
Hello world!
Numeric integer
You can directly operate on integers in Python (+,-,*,/)
>>> 3 + 25>>>
Floating point number
Python will be a floating-point number with decimals
35 / 217.5>>> 35 / 2.017.5
The number of decimal digits contained may be indeterminate
>>> 35 / 2.0117.412935323383085>>> 0.2 +0.10.30000000000000004>>>
Use function ser () to avoid type errors
#打印数据类型
Age = Input ("Age:")
Print (Type (age))
age = Int (input ("Age:"))
#查询数据类型
Print (Type (age))
#查询并转换数据类型为字符串
Print (Type (age), type (str))
Age:15
<class ' str ' >
Age:15
<class ' int ' >
<class ' int ' > <class ' str ' >
Python Learning (c) variables and simple data types