Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit ef503be

Browse files
添加chapter_1输出的基础使用案例
1 parent 180ad30 commit ef503be

File tree

1 file changed

+88
-0
lines changed

1 file changed

+88
-0
lines changed

‎chapter_1/print.py‎

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
# 打印数字Number
2+
'''
3+
int(有符号整型)
4+
long(长整型[也可以代表八进制和十六进制])
5+
float(浮点型)
6+
complex(复数)
7+
'''
8+
9+
# 赋值整型变量
10+
print(1) # 1
11+
12+
# 长整型 尝试失败
13+
#print(51924361L)
14+
15+
# 浮点型
16+
print(1000.0) # 1000.0
17+
18+
# 复数
19+
print(3.14j) # 3.14j
20+
print(3.14) # 3.14
21+
print(.876j) # 0.876j
22+
23+
# 打印数字计算
24+
print(1+1) # 2
25+
26+
# 打印英文字符串
27+
print("hello watermelon!") # hello watermelon!
28+
29+
# 打印中文字符串
30+
# python3 默认支持UTF-8格式 不用设置编码格式
31+
print("欢迎来到西瓜的世界") # 欢迎来到西瓜的世界
32+
33+
# python2 不支持UTF-8格式 需要设置编码格式 否则遇见中文会报错
34+
print("欢迎来到西瓜的世界")
35+
36+
'''
37+
Non-ASCII character '\xe4' in file print.py on line 2,
38+
but no encoding declared;
39+
see http://www.python.org/peps/pep-0263.html for details
40+
'''
41+
42+
# -*- coding: UTF-8 -*-
43+
# 或者
44+
# coding=utf-8
45+
# 可以选择上面两种设置编码格式中一种就好了
46+
print("欢迎来到西瓜的世界") # 欢迎来到西瓜的世界
47+
48+
# 打印布尔值
49+
# 注意python中布尔值的首字母是大写的
50+
# print(true) # name 'true' is not defined
51+
print(True) #True
52+
print(False) #False
53+
54+
# List(列表) 可变
55+
d_list = [66.25, 333, 333, 1, 1234.5]
56+
print(d_list) # [66.25, 333, 333, 1, 1234.5]
57+
58+
# Tuple(元组) 不可变
59+
d_tuple_1 = 12345, 54321, 'hello!'
60+
d_tuple_2 = ((12345, 54321, 'hello!'), (1, 2, 3, 4, 5))
61+
print(d_tuple_1) # (12345, 54321, 'hello!')
62+
print(d_tuple_2) # ((12345, 54321, 'hello!'), (1, 2, 3, 4, 5))
63+
64+
# Sets(集合){}
65+
d_set = {'apple', 'orange', 'apple', 'pear', 'orange', 'banana'}
66+
print(d_set) # {'apple', 'orange', 'apple', 'pear', 'orange', 'banana'}
67+
68+
# Dictionaries(字典)
69+
d_dic = {'jack': 4098, 'sape': 4139}
70+
print(d_dic) # {'jack': 4098, 'sape': 4139}
71+
72+
# 打印数据类型检测
73+
d_list_1 = [{'name':'melon','age':1},{'name':'water','age':2}];
74+
print(isinstance(d_list_1,list)) # True
75+
print(isinstance(d_list_1,dict)) # False
76+
print(isinstance(d_list_1,set)) # False
77+
78+
d_dic_1 = dict({'name':'melon','age':[1,2]})
79+
#{'name':'melon','age':[1,2]]},{'name':'water','age':[3,4]};
80+
print(isinstance(d_dic_1,list)) # False
81+
print(isinstance(d_dic_1,dict)) # True
82+
print(isinstance(d_dic_1,set)) # True
83+
84+
d_set_1 = set([1, 2, 3])
85+
#{'name':'melon','age':[1,2]]},{'name':'water','age':[3,4]};
86+
print(isinstance(d_set_1,list)) # False
87+
print(isinstance(d_set_1,dict)) # False
88+
print(isinstance(d_set_1,set)) # True

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /