python入门day1

今天大致了解python这门语言的强大功能,以及人工智能时代掌握编程语言的必要性,加深了我队对这么课程的学习兴趣。
接下来在老师的教学中学习了一些基础的语法,以下是相关的整理:
print('hello world!') ''' print('hello world!') ''' # name = 'tank' # # print(name) # id,type,value x = 10 y = 10 ''' python小计数池(python优化机制): 在变量值产生后指定的范围内, 在内存中事先开辟一块内存空间, 然后分别把指定范围内的变量存放进去。 ''' # print(id(x)) # print(id(y)) # name = 'tank' # print(type(x)) # print(type(name)) # 判断值是否相等 # print(x == y) # 判断id是否相等 # print(x is y) # 常量(常量也是变量,在python中大家都规定只要是大写的变量都称之为常量) SCHOOL = '安徽工程大学' # 用户与程序交互 # name = input('input your name:') # pwd = input('请输入密码:') # # print(name, pwd) # print(type(name), type(pwd)) ''' python2: raw_input() python3: input() ''' # 数字类型 # 整型int # number = 100 # int(100) # number2 = int(100) # print(number) # print(number2) # 浮点型 float # sal = 15.0 # float(15.0) # sal2 = float(15.0) # print(sal) # print(sal2) # 字符串类型 # name = 'tank' # name2 = "tank" # content = ''' # 1r1r1r # 21r12r1 # r12r # 12r1r21 # r12r1r2 # 12r1r # ''' # # print(name, name2, content) # python中字符串可以相加、相乘 # print('tank ' * 5) # print('tank' + 'jam') # print('tank', 'jam') # 列表类型 # []括号内以逗号隔开,可存放多个不同类型的值。 # list1 = ['张曼曼', 'tank', '涂懿磊', 11, 1.0, ['jason', 200]] # print(list1[0]) # print(list1[5][0]) # 字典类型 # 在{}内,都逗号隔开,可存放多个值,每个值以key: value的形式存储 # 存 # dict1 = {'name': "tank", "age": 18} # {name="tank", "age"=18} # 取 # print(dict1["name"]) # 布尔类型 # True or False # print(10 == 10) # True # print(10 == 11) # False # 注意: 所有数据类型都自带布尔, 0、None、空都为False # if 0: # print('111') # # if None: # print('111') # # if []: # print('111') # # else: # print('222') # 格式化输出 # 可以在输出时给字符串类型做一次替换 # %s占位符,%d可以替换数字类型 # number = input('请输入:') # str1 = ''' # 尊敬的用户,您的话费余额为%s元。 # ''' % number # # print(str1) # for循环 # list1 = [1, 2, 3, 4, 5] # for line in list1: # print(line) # for line in range(1, 10): # print(line) # dict1 = {'name': "tank", "age": 18} # for key in dict1: # print(key) # print(dict1[key])

# '''
# str1='my name is xxx,my age is 18'
# #祛除左右空格strip
# print(str1)
# print(str1.strip())
# #切分split
# list2=str1.split(' ')
# print(list2)
# str2='my name is xxx,my age is 18'
# for line in str2:
#     print(line,end=" ")
# str6 = 'my name in Tank'
# print(str6.lower())
# print(str6.upper())#lower 小写    upper 大写
# print(str6.startswith('my')) #startswith   判断前面  endswith 判断后面
# print(str6.startswith('My'))
# print(str6.endswith('tank'))
# #fomat 三种玩法
# str7 = 'my name in {},my age is{}'
# str7=str7.format('tank',18)
# print(str7)
#
# str7='my name in {1},my age is{2}'
# str7=str7.format('tank',18,111)
# print(str7)
#
# str7='my name in {name},my age is{age}'
# str7=str7.format(name='tank',age=18)
# print(str7)
# '''
# # join 对列表中的数据按照某种标识拼接 拼接要为字符串类型
# name ='tank'
# age='20'
# print(':'.join([name,age]))
# #replace
# str8 ='old new'
# str8=str8.replace('old','new')
# print(str8)
# #isdigit 判断字符串是否为数字
# ID =input('请输入')
# print(ID)
# print(ID.isdigit())
list1=['tank',18,'womale',3.0,9]
print(list1[4])
print(list1[-2])


# '''
# str1='my name is xxx,my age is 18'
# #祛除左右空格strip
# print(str1)
# print(str1.strip())
# #切分split
# list2=str1.split(' ')
# print(list2)
# str2='my name is xxx,my age is 18'
# for line in str2:
#     print(line,end=" ")
# str6 = 'my name in Tank'
# print(str6.lower())
# print(str6.upper())#lower 小写    upper 大写
# print(str6.startswith('my')) #startswith   判断前面  endswith 判断后面
# print(str6.startswith('My'))
# print(str6.endswith('tank'))
# #fomat 三种玩法
# str7 = 'my name in {},my age is{}'
# str7=str7.format('tank',18)
# print(str7)
#
# str7='my name in {1},my age is{2}'
# str7=str7.format('tank',18,111)
# print(str7)
#
# str7='my name in {name},my age is{age}'
# str7=str7.format(name='tank',age=18)
# print(str7)
# '''
# # join 对列表中的数据按照某种标识拼接 拼接要为字符串类型
# name ='tank'
# age='20'
# print(':'.join([name,age]))
# #replace
# str8 ='old new'
# str8=str8.replace('old','new')
# print(str8)
# #isdigit 判断字符串是否为数字
# ID =input('请输入')
# print(ID)
# print(ID.isdigit())
list1=['tank',18,'womale',3.0,9]
print(list1[4])
print(list1[-2])
print(list1[1:5:2])

print(len(list1))
#追加 append()
list1.append('sjkd')
print(list1)
#删除 pop()默认最后一个-1
print(list1.pop())
print(list1.pop(0))
print(list1)
list1.
#循环

课后作业部分:

name = " alex"
name = name.strip()
print(name)
name1 = name.startswith('al')
print(name1)
name2 = name.endswith('x')
print(name2)
name3 = name.replace('l', 'p')
print(name3)
name4 = name.split('l')
print(name4)
print(name.upper())
print(name.lower())
print(name[2])
print(name[1:4])
print(name[-2:-1])
print(name.index('e'))
print(name[0:len(name)-1])

总结:作为最受欢迎的程序语言之一python有以下优点

  • 1.易于学习:Python有相对较少的关键字,结构简单,和一个明确定义的语法,学习起来更加简单。

  • 2.易于阅读:Python代码定义的更清晰。

  • 3.易于维护:Python的成功在于它的源代码是相当容易维护的。

  • 4.一个广泛的标准库:Python的最大的优势之一是丰富的库,跨平台的,在UNIX,Windows和Macintosh兼容很好。

  • 5.可嵌入:可以将Python嵌入到C/C++程序。

 

上一篇:day01 python基础


下一篇:通俗易懂的讲解一下Java的代理模式