为了账号安全,请及时绑定邮箱和手机立即绑定
课程 \ Python3 入门教程(新版)

Python3 入门教程(新版)

2-2 第一个Python程序
# coding=utf-8
print"hole wrod")
2023-01-06 查看完整代码
3-1 Python基础数据类型
# Enter a code
print(type(3.1415926))
print(type('learn python in imooc'))
print(type(100))
print(type(0b1101))
2023-01-08 查看完整代码
3-2 Python定义变量的方法
# Enter a code
x = "Price"
y = "fuck"
print(x, y)
2023-01-06 查看完整代码
3-3 Python的整数与浮点数
# Enter a code
a=3.12
b=1.57
print(round(a*b))
2023-01-06 查看完整代码
3-4 Python的布尔类型
# Enter a code
a = 'python'
print('hello,', a or 'world')
b = ''
print('hello,', b or 'world')
2023-01-06 查看完整代码
3-5 Python的字符串
# Enter a code
s = 'special string: \', ", \\, \\\\, \\n, \\t'
print(s)
2023-01-06 查看完整代码
3-6 Python中raw字符串与多行字符串
# Enter a code
print(r'''To be, or not to be": that is the question.
Whether it's nobler in the mind to suffer''')
2023-01-08 查看完整代码
3-7 Python的字符串format
# Enter a code
print('Life is short, {}'.format('you need Python'))
print('Life is short, you need {l}'.format(l='Python'))
2023-01-08 查看完整代码
3-8 Python的字符串编码
# coding: utf-8
print('这是一句中英文混合的Python字符串:\n{}'.format('Hello World!'))
print('这是一句中英文混合的Python字符串:\n{}'.format('Hello World!'))
2023-01-08 查看完整代码
3-9 Python的字符串切片
# Enter a code
str='AABCDEFGHHIJ'
print(str[1:9])
2023-01-08 查看完整代码
4-1 Python之if语句
# Enter a code
age = 19
if age>=18:
print('teenager')
else:
print('adult')
2023-01-08 查看完整代码
4-2 Python之if-else语句
# Enter a code
age=10
if age>=18:
print('teenager')
else:
print('adult')
2023-01-08 查看完整代码
4-3 Python之if-elif-else语句
# Enter a code
age = 10
if age>=50:
print('elderly')
elif 50>age>=20:
print('adult')
elif 20<=age<18:
print('teenager')
elif 3<=age<18:
print('kid')
else:
print('baby')
2023-01-08 查看完整代码
4-4 Python之for循环
# Enter a code
L = [75, 92, 59, 68, 99]
sum = 0.0
for s in L:
sum+=s

print(sum/5)
2023-01-08 查看完整代码
4-5 Python之while循环
# Enter a code
num = 1
sum = 0
while num <= 10:
sum += num
num += 1

print(sum)
2023-01-08 查看完整代码
4-6 Python之break跳出循环
# Enter a code
num = 0
sum = 0
while True:
if num > 1000:
break
if num % 2 == 0:
sum = sum + num
num = num + 1
print(sum)
2023-01-08 查看完整代码
4-7 Python之continue继续循环
# Enter a code
n = 0
s = 0
while n <= 1000:
n += 1
if n % 2 == 1:
continue
s +=+ n
print(s)
2023-01-08 查看完整代码
4-8 Python之嵌套循环
# Enter a code
s1 = 'ABC'
s2 = '123'
s3 = 'xyz'
for x in s1:
for y in s2:
for z in s3:
print(x+y+z)
2023-01-08 查看完整代码
5-1 什么是容器、什么是list
# Enter a code
scoree = ['Alice', 'Chinese', 92, 'Math', 75, 'English', 99]
print(scoree)
2023-01-08 查看完整代码
5-2 Python按顺序访问list
# Enter a code
List1 = ['Alice', 66, 'Bob', True, 'False', 100]
for item in List1:
if type(item) == 'int' and item % 2 == 0:
print(item)
2023-01-08 查看完整代码
首页上一页123下一页尾页
意见反馈 帮助中心 APP下载
官方微信