day1 preview
About python
1python birth
1989 R & D
field
Cloud computing, web development, system operation and maintenance, scientific computing, artificial intelligence, reptiles, graphical GUI
python programming language
Compiled and interpreted, static and dynamic languages, strongly typed and weakly typed Definition Language
python installation
URL:
1. Open's official website: http://www.python.org, click on Downloads to download
2. Scroll down and select the corresponding version: Python3.6.3
3. The system selects the corresponding installation package
4, the download is complete
5, the installation
6, verify successful configuration
打开电脑的终端(黑窗口),输入 python回车进去python解释器
7, exit the terminal python
在终端中 >>> 输入exit()
Getting python
1.1 Output
Mac Launch Pad - Other - terminal - type vim filename - press the keyboard i - input - Exit Press esc - Input:! Wq - Enter
1.2 Variable
name 是一个变量名
= 是一个赋值操作 赋值就是将值交给name
'Meet' 是一个值
1.2.1 the definition of variables
Variable names consist of letters, numbers, underscores
Prohibit the use of variable name starts with a number
Prohibit the use of the name Python keywords and built-in functions
Keywords are as follows:
['False', 'None', 'True', 'and', 'as', 'assert', 'break', 'class', 'continue', 'def', 'del', 'elif', 'else', 'except', 'finally', 'for', 'from', 'global', 'if', 'import', 'in', 'is', 'lambda', 'nonlocal', 'not', 'or', 'pass', 'raise', 'return', 'try', 'while', 'with', 'yield']
We do not recommend the use of Chinese and Pinyin
Variable name to have meaning
Variable names are case sensitive
Recommended wording:
- Hump body: AgeOfOldboy = 56
- Underline: age_of_oldboy = 56
1.2.2 Assignment of variables
name1 = 'Meet'
name2 = 'Guo'
name1 = 'Meet'
name2 = name1
Small advanced variable 1.2.3
age1 = 18
age2 = age1
age1 = 12
age3 = age2
print(age1,age2,age3)
1.3 Constant
Constant is the variable name in uppercase.
1.4 Notes
# print('hello') 这样就是对这个代码进行注释,并且这个代码不会执行
'''
print(1)
print(2)
这种就是多行注释,
1.5 basic data types
Number, string, boolean
1.5.1 Plastic
num1 = 2
num2 = 3
print(num1 + num2)
# 结果: 5
# 整型就和我们学的数学一样可以进行加减乘除
1.5.2 String
String addition
num1 = 2
num2 = 3
print(num1 + num2)
# 结果: 5
# 整型就和我们学的数学一样可以进行加减乘除
String multiplication
str*int name = '坚强'
print(name*8)
1.5.3 Boolean
bool is a Boolean value, a Boolean value total is divided into two states
True is true
False is false
print(3>7)
结果: False
print(7>3)
结果: True
1.6 input
s = input('请输入你喜欢的东西')
1.6.1 enter a user name
#!/usr/bin/env python
#-*- coding:utf-8 -*-
#将用户输入的内容赋值给name变量
python2的写法
name = raw_input("请输入用户名:")
print name
python3的写法
name = input("请输入用户名:")
print(name)
1.7 if statement
The if statement
if 条件: #引号是将条件与结果分开。
结果# 四个空格,或者一个tab键,这个是告诉程序满足这个条件的结果。切记空格和tab键不能混合使用
1.7.1 determining if conditions
age = input("输入年龄:")
if int(age) >= 18:
print("成年了,能干成年人的事了")
1.7.2 Choose one ifelse
age = input('请输入您的年龄:')
if int(age) > 18:
print('你可以去网吧尽情的嗨皮了')
else:
print('你现在还不行啊!')
1.7.3 multiple options to a radio or not vote if elif
num = input('请输入要比较的数字:')
if int(num) >= 22:
print('可以扯证了')
elif int(num) >= 18:
print('成年了,可以干一些成年的事了')
elif int(num) < 18:
print('还是小屁孩')
1.7.4 multiple options Radio (mandatory) if elif else
num = input("请输入要比较的数字:")
if num > 60:
print("大了")
elif num < 60:
print("小了")
else:
print("猜对了")
1.7.5 Nested if
name = input('请输入名字:')
if name == 'meet':
age = input('请输入年龄:')
if int(age) == 18:
print('输入全部正确')
else:
print('年龄输入错误!')
else:
print('名字输入错误!')