Python基础语法

本文介绍了Python编程中常见的数据结构操作,包括列表的反转、插入、排序,元组的使用,字典的遍历以及字符串的处理。此外,还展示了时间函数的运用,如获取当前时间并格式化输出。这些基础知识对于Python初学者来说十分关键。
摘要由CSDN通过智能技术生成

1、列表操作

b=["青岛","烟台","济南"]
print(b)
b.reverse()
print(b[0])
print("济南" in b)
b.append("德州")
print(b)
b.insert(3,"潍坊")
print(b)
b.sort()
print(b)

2、元组操作:元组即只读列表

tap = (2,3,4)
print(tap)

3、字典操作

dict={"abc":10,4:"115a"}
for value in dict.values():
    print(value)
for key in dict.keys():
    value = 0
    value = dict[key]
    print(value)
print(dict["abc"])

4、字符串操作

squeue = "QUE stu best best best!"  #squeue是字符串
list = squeue.split()   #list是字符数组
dict = {}   #dict是字典
for a in list:
    if a in dict:
        dict[a]+=1
    else:
        dict[a]=1
print(dict)
name = "123 456"
print(name)
print(name[4:6])
akk = name + "999"
print(akk)

5、时间函数

import time
print time.localtime()
localtime = time.asctime(time.localtime())
print(localtime)
print time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值