python
1.1输出函数
1)
print(“Hello World!”)
运行后会输出双引号中的内容
2)
print("Hello world","i love python!")
逗号表示前者和后者之间有一个空格
3)
print("abc"+"aaa","hehe")
加号不是加法运算,而是字符串连接符,加号左右两端的文本信息会连在一起打印出来
4)
print("hello"*10)
*n表示该段文本信息重复n次
print("hello\n"*10)
\n为换行符
1.2数据类型
基本数据类型
数字类型:整数(int),浮点数(float),复数
字符串类型(str)
布尔类型(bool)
其他类型:元组(tuple),列表(list),字典 (dict ),集合
使用type函数查看当前数据的类型
print(type("hello"))
print(type(0x110))
print(type(10.24))
print(type(True))
1.3运算符
+号两边都是字符串时,+为连接符
两边数据类型不一致时报错,因为字符串不能和其他非字符串相加。
1.4转换函数
int() 函数:将一个字符串或数字转换为整型。
str()函数: 将其他一切的数据转字符串
float()、bool()同理
print( int("10010101",2) )
print(int("helloworld",36))
#可以把其他进制转换为十进制输出
print( int("123") + 123 )
print( "123" + str(123) )
两个转换的不同,结果也不同