小白python学习——学习基础时遇到的函数、知识点总和(自己觉得比较重要的函数和知识点)

#字符串——大小写
def str():
    s="abcde"
    print(s.title())  # title : 每一个单词首字母大写,其他全小写
    print(s.upper())  # upper : 全部大写
    print(s.lower())  # lower : 全部小写
#str()
#-------------------------------------------------------------



def _nt():
    print("hello world\n\thello world")                     #    \t     's function
    print("Languages:\n\tPython\n\tJava\n\tC\C++")          #    \n\t   's function
#_nt()
#-------------------------------------------------------------



#字符串——删除空白
def _remove():
    s=" hello world "
    print(s)
    print(s.lstrip())      # (开头)首空格
    print(s.rstrip())      # 末尾空格
    print(s.strip())       # 首、尾空格
#_remove()
#--------------------------------------------------------------



#列表——插入元素
def list_append():
    list=["I","LOVE","YOU"]
    list.append("yh")            #list.append(what)     列表末尾添加数据
    print(list)
    list.insert(0,"yh")
    print(list)                  #list.insert(num,what) 列表具体位置,添加数据其他往后挪一位
    list.insert(-1,"ZY")
    print(list)
#list_append()
#--------------------------------------------------------------





#列表——删除元素
def list_del():
    s=["I","LOVE","YOU","ZY"]
    del s[-1]                     #del s[i]  删除已知位置的列表值
    print(s)


    s=["I","LOVE","YOU","ZY"]
    print(s.pop())                #s.pop()   删除并得到末尾的列表值
    print(s)


    s=["I","LOVE","YOU","ZY"]
    s.remove("ZY")                #s.remove("ZY") 删除列表已知值
    print(s)
#list_del()
#--------------------------------------------------------------




#列表——由小到大排序 / len()确定元素个数
def list_sort():
    s=['a','d','c','e','b']
    s.sort()                  # s.sort()     由小到大排序:  数字按数字  英文按字母表 abcde
    print(s)
    s.reverse()
    print(s)
    s.reverse()               # s.reserve()   逆序排列,再逆序一次就可以返回原来的
    print(s)
    x=len(s)
    print(x)
#list_sort()
#--------------------------------------------------------------





#列表——数字列表找最大最小值等
def MAX_AND_MIN():
    num=[1,2,3,4,5,6,7,8,9,0]
    print(max(num))                   #   max(self) : 找最大值
    print(min(num))                   #   min(self) : 找最小值
    print(sum(num))                   #   sum(self) : 求和
#MAX_AND_MIN()
#--------------------------------------------------------------






#列表——元组
def another_list():
    s=(200,100)
    print(s[0])
    #             print(s[-1])            #元组是无法改变的列表   这里改变s【0】=50  is  wrong!
    #              s[0]=50
    #             print(s[0])
#another_list()
#--------------------------------------------------------------






#If语句——列表
def _if():
    s=["zy","yh","lx","cj"]
    a="zy"
    if a in s:
        print("YES")               #  if 中直接not in  或者  in  来判断是否在列表中
    if a not in s:
        print("NO")
#_if()
#-------------------------------------------------------------





#函数——import(模块)
import pizza as zy    #from pizza import print.one         两种调用方法          as是别名,把pizza叫做zy
#zy.print_one()
#--------------------------------------------------------------






#类——class XX():
class Restaurant():
    def __init__(self,name,type):
        self.name=name
        self.type=type
    def describe_restaurant(self):
        print(self.name+"and"+self.type)
    def open(self):
        print("The restaurant is open")
retstaurant=Restaurant("AI BOAT","chinese food")          #具体内容看书的简介 P140
#retstaurant.describe_restaurant()
#retstaurant.open()
#--------------------------------------------------------------



















































































评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值