python 磨刀霍霍向猪牛

print('hello python world')

message = 'hello python world second'

print(message)

#变量的命名可以是字母数字下划线, 以字母或下划线开头,不能以数字开头。不能用特殊的字符。
message = 'hello python crash course world'

print(message)

#字符串 字符转换, 拼接
msg = 'This is a string'
print(msg.title())
print(msg.upper())
print(msg.lower())

first_name = 'huo'
last_name = 'yi feng'
full_name = first_name + ' ' + last_name
print(full_name.title())
msg = '\tPython';
print(msg)
msg = ' hello world '
print(msg)
print(msg.rstrip())

msg = 'Hello Eric, would you like to learn some Python today';
print(msg)

language = 'no zuo no die';
print(language.title())


##整数(+,-,*,/)

a = 1
b = 9
num = a + b
print(num)
print(a/b)
#浮点数

age = 23;
message = "Happy " + str(age) + "rd Birthday";
print(age);

message = 1,2
print(message)

bicycles = ['trek', 'cnnondale', 'redline', 'specialized'];
print(bicycles)
print(bicycles[0])
print(bicycles[0].title())
#在最后一个元素后添加数据
bicycles.append('dubati')
print(bicycles)
#指定元素添加数据
bicycles.insert(1, 'suzuki')
print(bicycles)
#删除指定元素
del bicycles[0]
print(bicycles)
#删除列表最后一个元素
bicycles.pop()
print(bicycles)
#remove 删除指定值
bicycles.remove('redline')
print(bicycles)

 


#排序
peoples = ['girl', 'boy', 'baby', 'father', 'mother']
#peoples.sort()
#peoples.sort(reverse = True)
#print(sorted(peoples))
#print(sorted(peoples, reverse = True))
peoples.reverse()
print(peoples)
print(len(peoples))

traver = ['tianjin', 'shanghai', 'shenzheng', 'beijing', 'chongqing']
traver.sort();
print(traver)
#返回最后一个元素
print(traver[-1])

#循环遍历,多条语句放在一起,并且同时都缩进, 才认为是循环主体
magicians = ['anni', 'lucy', 'silila', 'lilei']
for magician in magicians:
print (magician)
#print(magician.title())


for values in range(1, 6):
print(values)

numbs = list(range(1, 6))
print(numbs)

numbs = list(range(2, 11, 2))
print(numbs)
print(min(numbs))
print(max(numbs))
print(sum(numbs))
#切片的使用
print(numbs[:2])
print(numbs[-1])

numbs_list = numbs
numbs.append('hello')
print(numbs)
print(numbs_list)

numbs_list2 = numbs[:]
numbs_list.append('test')
print(numbs_list)
print(numbs_list2)

#原主不能修改
yuanzu = (1,2)
print(yuanzu[1])

#条件语句

if 2 == yuanzu[1]:
print(True)
test_numbs_list = 'hello'

if test_numbs_list in numbs_list:
print(True)

if 'a' not in numbs_list:
print(True)

if ('test' not in numbs_list) and (test_numbs_list in numbs_list):
print(True)
else:
print(False)

age = 4;
if (age < 4):
print('free')
elif (age < 18):
print('$5')
else:
print('$20')

#字典
alien_0 = {'color':'green', 'point':3}
print(alien_0['color'])
alien_0['x_position'] = 100
alien_0['y_position'] = 2;
print(alien_0)

favorite_languages = {
'lucy': 'english',
'lilei': 'chinese',
'xiaomi' : 'tecloligy'
}

#循环遍历
for name, language in favorite_languages.items():
print(name+ ' :' + language)

for name in favorite_languages.keys():
print(name)
for language in favorite_languages.values():
print(language)

alien_0 = {'color':'green', 'point':3}
alien_1 = {'color':'blue', 'point':3}
alien_2 = {'color':'red', 'point':3}
alien = [alien_0, alien_1, alien_2]

for alien_itme in alien:
print(alien_itme)

new_aliens = []
for alien_key in range(5):
alien_item = {'color': 'green', 'point':3}
new_aliens.append(alien_item)

print(new_aliens)

lists = ['an', 'send', 'pass']
new_list = [];
while lists:
list_item = lists.pop()
new_list.append(list_item)
print(new_list)

 

上一篇:RPA学习笔记04


下一篇:【四二学堂】基于UiBot实现的RPA项目-携程机器人订票