Python基础一,,一、介绍python


一、介绍

python部分以python3为基础进行阐述

print("Hello World!")

二、变量

python没有常量的概念,一切皆可以是变量,但习惯性的用全大写字母组成的字符代表常量,AGE_OF_RAP = 56

变量是指可变化的量,可用来代指内存里某个地址中保存的内容。有如下规则:

1.变量名只能是 字母、数字或下划线的任意组合

2.变量名的第一个字符不能是数字

3.以下关键字不能声明为变量名[‘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‘]

三、字符串

字符串是python基础数据类型之一,由单引号或双引号组成,如‘i love python‘或"i love python",具有不可变性,因此一旦建立便不能修改

四、读取用户输入

python3弃用了raw_input(),只用input()进行读取用户的输入

name = input("What is your name?")

五、列表

重要的基本数据类型之一

list1 = [‘physics‘, ‘chemistry‘, 1997, 2000]list2 = [1, 2, 3, 4, 5 ]list3 = ["a", "b", "c", "d"]

六、字典

重要的基本数据类型之一

dict1 = { ‘abc‘: 456 }dict2 = { ‘abc‘: 123, 98.6: 37 }

七、流程控制

x = int(input("请输入您的总分:"))if x >= 90:    print(‘优‘)elif x>=80:    print(‘良‘)elif x >= 70:    print(‘中‘)elif x >= 60:    print(‘合格‘)else:    print(‘不合格‘)

八、循环

#!/usr/bin/python count = 0while count < 9:   print ‘The count is:‘, count   count = count + 1 print "Good bye!"

Python基础一

评论关闭