Computer Basics
Computer Organization
Input and output devices CPU hard drive memory storage cards Display Power
CPU central processing various data processing equivalent to the human brain
Memory for storing data
Hard disk to store data
operating system
Control computer work flow software
application
Software installed on top of the operating system is the application
to sum up
CPU human brain
Memory person's temporary memory
The hard man of permanent memory
Operating system control computer hardware work processes
Application software is installed on top of the operating system
Introduction to Python
Applications
web development (writing Web site from scratch) Artificial Intelligence reptiles (large quantities crawling data network) Financial Analysis cloud computing
The difference Python2 and Python3
Python2 source code is not uniform repeat
Python3 no unified source code duplication
Programming language
Compiled and interpreted static and dynamic languages strongly typed and weakly typed language Definition Language
Compiled
Advantages : speed fast disadvantages : slow development efficiency
Interpreted
Advantages : fast development efficiency disadvantages : running slow
Python's strengths and weaknesses
advantage
easy to understand
Development efficiency is very high, class libraries (third-party libraries) particularly
High-level language, regardless of the underlying details such as memory
Portability across platforms
Scalability in Python the part program is written in C or C ++
Embeddability, Python may be embedded in C or C ++
Shortcoming
Slow
Code can not be encrypted
Thread can not take advantage of multi-CPU
Python species
Cpython(Python转C语言) Jyhton (Python转java) IronPython (Python转C#)
PyPy(Python转Python编译)(特殊)
Getting Started with Python's
print() 输出
variable
print(12+34)
print((12+34)*2)
print(((12+34)\*2)*3)
a = 12+34
b = a*2
c = b*3
print(a) # 注意打印a的时候不能加引号
Variable rules
Variables are letters, numbers, underscores
Prohibit begin with a number
Prohibit the use of Python keywords
and,as,assert,break,class,continue,def,del,elif,else,except,exec,finally,for,from,global,if,import,in,is, lanbda,not,or,pass,print,raise,return,try,while,with,yield
You can not use Chinese and Pinyin
Variable names are case-sensitive
Recommended wording
CamelCase:
Omine
Komine
Underline name:
The official recommended
7. The variable name has to be descriptive
a = 12
变量名 赋值 值
age = 18
age1 = age
age2 = age1
age = 19
print(age,age1,age2) #19 18 18
constant
ALEX = 2022
Constant name in all caps
Note
Notes two ways
# Single-line comments (comment when the line) can not wrap
"" "" "" Or '' '' '' may wrap the multi-line comment
Data Types acquaintance
type (type)
Integer (int) Digital
String (str) Character 'string' 'string' '' 'string' ''
"my name is meet ,i'm 22 years ol
a = 'alex'
b = 'wusir'
print(a+b) # alexwusir 字符串拼接 注意:只能和字符串相加
# -*-coding:utf-8 -*-
a = '坚强'
print(a*8) #坚强坚强坚强坚强坚强坚强坚强坚强 字符串乘 注意:只能和数字相乘
Boolean value (bool) right or wrong
True False
1 0
User interaction (input)
input Output
account password
# -*-coding:utf-8 -*-
input("提示语句") #提示语句
# -*-coding:utf-8 -*-
s = input("请输入账号")
print(s) # s
# -*-coding:utf-8 -*-
user = input("请输入账号:")
password = input("请输入密码:")
print(user)
print(password) # user password
# -*-coding:utf-8 -*-
import getpass
user = input("请输入账号:")
password = getpass.getpass("请输入密码:")
print(password)
print(user) # 密码不可见 只能在cmd中使用
acquired digital input type
# -*-coding:utf-8 -*-
# num = input("请输入数字:")
a = 56
print(type(a)) # class 'int'
b = 'alex'
print(type(b)) # class 'str'
# -*-coding:utf-8 -*-
num = input("请输入数字")
print(type(num)) # class 'str' 由此可知,由input获取到的都是字符串
Flow control statements
if
if if
if the keyword space colon condition
Indent results
print(55)
if 3>2:
print("你好美,小学") #打印数字不加"", 打印汉字必须加"".
print("我说的假话")
# 55
你好美,小学
我说的假话 #单if
if else
if else
If otherwise
if 条件:
结果
else:
结果
if 4>3:
print("嗨")
else:
print("hello")
if elif
if elif
If we if
if 条件:
结果
elif 条件:
结果
elif 条件:
结果
if 3>4:
print("真NB")
elif 5>6:
print("更NB")
elif 3>2:
print("稳")
elif 55>1:
print("没毛病") # "稳"
if if
if 3>2:
print(1)
if 4>3:
print(4)
if 5>1:
print(6) # "1" "4" "6"
if nested
if 条件:
结果
if 条件:
结果
if 条件:
结果
Flow control statements summary
age = int(input('请输入内容:')) #提示语句
if age>18:
print("可以去一些比较嗨皮的场所")
if age>22:
print("可以扯证了")
elif 18<age<20:
print("可以洗j")
else:
print("可以洗z")
else:
print("兄弟,买盘吗...") #输入18,打印"兄弟,买盘么" 输入19,打印"可以去一些比较嗨皮的场所","可以洗j" 输入21,打印"可以去一些比较嗨皮的场所","可以洗z"