python_day01

1、变量

  a、类型:

  描述:就如调料罐子,专门的罐子放专门的佐料。盐、味精、油放在不同的容器而已,容器也有大小之分(类型转换

  # -*- coding:utf-8 -*-

  # Author:chenpi

  name = "chenpi"

  name1=name

  print(name," is a name")

  name = "jiege"

扫描二维码关注公众号,回复: 1458566 查看本文章

  print(name,name1)

  

   原理:name通过引用指向了内存中 "chenpi"在内存中的地址0xxx,把name的地址赋给了name1,所以name1 的地址变成了"chenpi"在内存中的地址,所以当name改变了新的引用并不会影响到name1值的改变,因为两个变量所指的内存地址不一样。

   b、变量名

   下划线

   驼峰

   c、变量的使用

  

2、常量

  a、变量名

   大写:PIE

3、字符编码

  二进制:

  2**n -1

  128 = 2**7-1

 

  a、ascii码

  b、GB2312 1980

  c、GBK 1995

  d、GB18030 2000

  e、Unicode #兼容所有中文,万国码

  f、UTF-8 可变长的Unicode #en:1byte zh:3byte

  

  注意:python2和python3有个小区别!

  八进制

  十六进制

4、用户交互

  2.x

  row_input:

  input:输入是什么就是什么 #没有引号那输入就是变量,有引号就是字符串

  3.x

  input:

5、类型转换

  int(input(“something !”))

  string(input(“something !”)) 

6、

流程控制:

  if... else

  if... elif ... else

  while

  for

  switch ... case:

   #continue

   #break

eg:if..elif...else

# -*- coding:utf-8 -*-
# Author:chenpi

age_of_chenpi = 18
guess_age = int(input("you guess age:"))
if guess_age == age_of_chenpi:
    print("Congrauation you guess right!!")
elif guess_age > age_of_chenpi:
    print("think bigger !")
else:
    print("think smaller...")

eg:while

# -*- coding:utf-8 -*-
# Author:chenpi

count = 0
age_of_chenpi = 18
while count < 3:

    guess_age = int(input("you guess age:"))
    if guess_age == age_of_chenpi:
        print("Congrauation you guess right!!")
        break
    elif guess_age > age_of_chenpi:
        print("think bigger !")
    else:
        print("think smaller...")
    count +=1
else:
    print("you have tried to many times ...fuck off !")

eg:for

# -*- coding:utf-8 -*-
# Author:chenpi

for i in range(10):
    print("----------",i)
    for j in range(10):
        print(j)
        if j >5:
            break

猜你喜欢

转载自www.cnblogs.com/chenpibky/p/9136387.html