python day1

1.变量

nums_of_alex

不允许数字开头,不允许特殊字符。可以下划线开头

以下关键字不能声明为变量名
['and', 'as', 'assert', 'break', 'class', 'continue', 'def', 'del', 'elif', 'else', 'except', 'exec', 'finally', 'for', 'from', 'global', 'if', 'import', 'in', 'is', 'lambda', 'not', 'or', 'pass', 'print', 'raise', 'return', 'try', 'while', 'with', 'yield']

a=3

id(a) 看内存地址

AGE_OF_OLDBOY     #全部都是大写 设定为常量 

2.  if  elif else 判断语句

强制缩进

3.

‘’‘

’‘’

#隐藏

4. 选中+tab键 整理代码

ctrl+?   隐藏

ctrl +d  复制

同一类型的数据可以相互操作,

字符不能与 整形相加比较。

5. while True :

count = 0 
while count < 3 :

  count +=1

判断 

if :

elif :

else:

for i in range(1,100,10)

 6.数据类型

int 

float

long

 拼接:

print("information of []:" "
name:[]" +name +"
Age:[]" +age +"
Job[]:" +job)
print("information of: Name:%s Age:%s Job:%s" %(name,age,job) )

单引号,双引号在python没有区别
age = int(input("age:"))
print("information of:
Name:%s
Age:%d
Job:%s" %(name,age,job) )

job = input("job:").strip() 去空格

7.列表

dir(name_list) #查看多少个参数
name_list.append("HELLO")

切片
a[0:5]
a[-3:-1] 取倒数2个

>>> a = [1,2,3,4,5,6,'a','b']
>>> a[0:3]
[1, 2, 3]
>>> b = [7,8,9,10,11]
>>> c = a +b

[ 'append', 'clear', 'copy', 'count', 'extend', 'index', 'insert', 'pop', 'remove', 'reverse', 'sort']

8.元组 (只读)

>>> t = (1,2,3,4)
>>> t
(1, 2, 3, 4)
>>> dir(t)

['count', 'index']

type(t)

 9.运算符

嵌套循环:

文件操作:

原文地址:https://www.cnblogs.com/jack2017/p/7103713.html