Python快速入门

 Python快速入门_第1张图片

Python快速入门_第2张图片 

PyCharm 常用快捷键

复制:Ctrl + d

删除:Ctrl + y

撤回:Ctrl + z

注释: Ctrl + /

方法跳转:Ctrl + B

最近编辑的文件 Ctrl +e

格式化:Ctrl + Alt + l  (个人修改成Ctrl + Shift + f)

换下一行:Shift + Enter

万能搜素:Shift +Shift

全局关键字搜索:Alt + Shift +r

错误代码修正提示:Alt +Enter

选中代码生成函数:Ctrl + Alt + m

选中代码生成try-except等 Ctrl + Alt + t

# 变量声明
name = "hello"

age = 19

price = 13.45

is_true = True

# 字符串截取
print(name[0:2])
# 查看数据类型
print(type(name), type(age), type(price), type(is_true))
# 转大写
print(name.upper())
# 是否相等 -> False
print("Hello" == name)

# 数组
a = array = [1, 2, 3, 4, 5]
# 索引操作数组
print(array[0], array[3])
# 添加元素
array.append(6)
array.extend(["a", "b", 90])
array.insert(0, "test")
# 替换2,下标从1开始,闭头开尾
array[2:5] = [7, 8, 9]
# 是否包含元素
print(1 in array)
# 获取数组长度
print(len(array))

print(array)
# 遍历数组,不换行打印
for i in array:
    print(i, end='')

print()
print("----------------------------")

# map
map = {"key1": 123, "key2": "ldj"}

# 遍历map
for key in map.keys():
    print(key)

print()
print("----------------------------")

for value in map.values():
    print(value)

print()
print("----------------------------")

for kv in map.items():
    print(kv)

# 获取用户输入
# name = input("what is your name ? ")
# print("我叫:" + name)
#
# # 类型转换
# birthday = input("请输入出生年份: ")
# age = 2024 - int(birthday)
# print(age)

# 运算符与比较运算符
print(3 + 5 - 3)
print(3 + 5 * 3)
print(3 + 5 / 3)

a = 4
# a除以2的2方 -> 1
print(a >> 2)
# a乘以以2的2方 ->16
print(a << 2)
# 10的3次方
print(10 ** 3)

x = 10
# 自增 -> 12
x += 2
print(x)
y = 10
# 自乘 -> 100
y *= 10
print(y)

# -> False
print(1 > 2)
# -> True
print(1 < 2)
# -> True
print(1 != 2)
print(1 == 2)
# -> True
print(1 <= 2)

# 逻辑运算符
num = 10
# -> True
print(num > 5 and num < 12)
# -> True
print(num > 5 or num < 12)
# -> True
print(not num > 12)

# 分支语句
temperature = 25
if temperature > 35:
    print("太热了")
elif temperature <= 25:
    print("很舒服!")
else:
    print("呆在家")

# 循环语句
i = 0
while i < 10:
    i += 1
    print("Hello Python")

for i in [0, 1, 2, 3, 4, 5]:
    print(i)

print("--------------------------------")

for i in range(5):
    print(i)

print("--------------------------------")

for i in range(2, 8):
    print(i)

print("--------------------------------")

for i in range(2, 8, 4):
    print(i)

print("--------------------------------")

# 元组 元素不可以改变
numbers = (1, 2, 3, 3)
print(numbers.count(3))
print(numbers.index(2))

Python快速入门_第3张图片

你可能感兴趣的:(python,python)