#模块 -- 包含定义的函数和变量的文件, .py 文件
import sys
for i in sys.argv:
print(i)
print('\npyhton 路径 \n:', sys.path)
'''
pyhton 路径
: ['E:\\python\\execise1', 'E:\\python\\execise1', 'C:\\Program Files\\Python38\\python38.zip', 'C:
\\Program Files\\Python38\\DLLs', 'C:\\Program Files\\Python38\\lib', 'C:\\Program Files\\Python38',
'C:\\Users\\FoX\\AppData\\Roaming\\Python\\Python38\\site-packages',
'C:\\Users\\FoX\\AppData\\Roaming\\Python\\Python38\\site-packages\\win32', 'C:\\Users\\FoX\\AppData\\Roaming\\Python\\Python38\\site-packages\\win32\\lib', 'C:\\Users\\FoX\\AppData\\Roaming\\Python\\Python38\\site-packages\\Pythonwin', 'C:\\Program Files\\Python38\\lib\\site-packages']
'''
import surport
surport.welcom('张三') #welcome 张三
#优先在当前项目的目录下检索, 然后再去上级目录检索怕, 没有就返回报错
surport.feibo1(10)
print(surport.feibo2(10))
'''
1
1
2
3
5
8
[1, 1, 2, 3, 5, 8]
'''
print(dir(sys))
#输入输出, print(*object, sep = '', end = '\n', file = sys.stdout, flush = False)
#object --- 支持多个打印对象, file --- 指定文本,不支持二进制文件
data = 'hello world'
print(data, data, sep = '---') #hello world---hello world
print('abc', end = '')
print('def') #abcdef
#格式化字符 -- format
ss = 'hello world'
print(str(ss)) # 强转换为字符串, 服务与机器
print(repr(ss)) # 转为字符串内容, 人看的
'''
hello world
'hello world'
'''
name = '张三'
age = 28
print('大家好, 我是{}, 今年 {}岁 '.format(name, age)) #大家好, 我是张三, 今年 28岁
#张三的 ip 地址是 1232135.3253
def display(name, ip):
return '{}的ip是{}'.format(name, ip)
print(display('王二', 123513425.325424)) #王二的ip是123513425.325424
#format 根据索引进行格式化
name = 'boo'
age = 19
work = '工地'
hobb = 'singing'
print('大家好, 我是{0}, 今年 {1}岁, 在{2} 工作, 喜欢{3}'.format(name, age, work, hobb)) #大家好, 我是boo, 今年 19岁, 在工地 工作, 喜欢singing
import math
print('PI 的近似值 {0:.2f}'.format(math.pi)) #PI 的近似值 3.14
table = {'taibao': 1, 'tiktol' : 2, 'huawei': 3}
for name, number in table.items():
print('{0:10}==> {1:10d}'.format(name, number))
'''
taibao ==> 1
tiktol ==> 2
huawei ==> 3
'''
table = {'huawei': 1, 'tencent': 2, 'bilibili': 3}
print('huawei: {0[huawei]: d}\nbilibili: {0[bilibili]: d}\ntencent: {0[tencent]: d}'.format(table))
'''
huawei: 1
bilibili: 3
tencent: 2
'''
#input-- 只要不换行都能被接收, 返回字符串形势
info = input()
print(info)
info1 = input().split()
print(info1)
'''
hello
hello
1 2 3 4
['1', '2', '3', '4']
'''
name = input('请输入姓名 : ')
print('{} 欢迎您'.format(name))
python基础二
最新推荐文章于 2024-06-21 12:33:31 发布