首页 > 代码库 > 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基础一
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。