【python】基础(三)

本文介绍了Python的基础操作,包括变量类型的查看、字符串处理、格式化输出、循环结构等,并演示了简单的文件读写操作。
# coding:utf-8
"""设置utf8编码,防止出现中文乱码的情况"""
'''type()函数可用来查看变量类型'''
print(type('你好!'))
#整理第三方库的网站 awesome-python

import sys
print(sys.path)  #查找库的安装路径
'''字符串replace'''
phone_number = '188-888-88888'
hiding_number = phone_number.replace(phone_number[:9],'*'*9)
print(hiding_number)
'''.format()实现批处理'''
city = input('write down the name of city:')
url = "http://apistore.baidu.com/microservice/weather?citypinyin={}".format(city)
print(url)
print('hello world!')
file = open('hello.txt', 'w')
file.write('hello world!')

'''replace的用法'''
word = 'python is lame!'
words=word.replace('lame', 'awesome')
print(words)

'''成员运算符 in/not in 和身份运算符 is/is not'''

'''
条件判断
if condition:
    do somethong
elif condition:
    do somethong
else :
    do somethong
'''
'''
循环
for是关键词,在关键词in后面所对应的一定是具有‘可迭代的’或者是像列表那样的集合形态的对象。
'''
for every_letter in 'hello world':
    print(every_letter)
for num in range(1,11):
    print(str(num)+'+1=',num+1,'end',sep='\n')
'''print输出控制: sep对同一个print有效,end对不同的print有效'''
'''python 除法取整数 //;取余数 %'''
nu = 1
while (nu<101):
    if (nu % 2 ==0):
        print(nu,end=' ')
    nu = nu+1
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值