《python3爬虫、数据清洗与可视化实战》第一章 python

2019-07-12  本文已影响0人  LZzzHe

1.1 python基本操作

1.1.1 python注释

#第一个注释
print ('Hello,World!')
'''
第一行注释
第二行注释
'''
print('Hello,World!')

1.1.2 多行语句

weekdays ="little Robert asked his mother for two cents.\
'what did you do with the money I gave you yesterday?'"
print(weekdays)

1.1.3 等待用户输入

print("Who are you?")
you = input()
print("Hello")
print(you)

1.1.4 变量命名

import keyword
keyword.kwlist

1.2 python的数据类型

1.2.1 数字

(1)数字类型

(2)运算类型

print(15//4) #整除运算,输出结果为3
print(15/4) #除法运算,输出结果为3.75
print(15%4) #取余运算, 输出结果为3

1.2.2 字符串

(1)字符类型

print('''Mike:  Hi,How are you?
LiMing:Ok,I am fine!''')

(2) 字符串的表示方式

print('What\'s your name?')
print(r"Newlines are indicated by \n")

(3)字符串的截取

str='Lingyi'
print(str[1:4]) # 输出结果为 ing

(4)字符串运算

1.2.3 列表

list = ['python',12,[1,2,3],3.14,True]

1.3.4 元组

tuple=('abc',56,'ly',67,5.2)

1.2.5 集合

age = {18,55,666,65,36}
print(age)
# 运行结果:{18,55,666,65,36}

1.2.6 字典

dic = {'key1':'value1','key2':'value2'}
dic['key3']='value3' # 字典添加数据的方法
del dic['key3'] # 使用del函数删除数据
上一篇下一篇

猜你喜欢

热点阅读