温习pycharm

---恢复内容开始---

title()

#修改首字母大小写

name.upper()

#全部大写

name.lower()

#全部小写

-------------------------------------

first_name = "ada"
last_name = "lovelace"
full_name = first_name + " " + last_name

print("Hello, " + full_name.title() + "!")

#符号也要引号起来

----------------------------------

rstrip()

#删除右侧空白

lstrip()

#删除左侧空白

strip

#删除全部空白

-----------------------------------------------

message = "Happy " + str(age) + "rd Birthday!"
print(message)

#类型容易发生错误‘

motorcycles = ['honda', 'yamaha', 'suzuki']
print(motorcycles)


motorcycles[0] = 'ducati'
print(motorcycles

#修改列表元素

motorcycles.append('ducati')

#在列表末尾增加元素

motorcycles.insert(0, 'ducati')

#在0索引位置插入元素

del motorcycles[0]

#删除元素del 

popped_motorcycle = motorcycles.pop()

#使用pop()把元素分裂出来储存到另外一个变量中,而且是从后边往前边删除

pop()#括弧中添加索引时会删除指定的元素。

如果不知道索引,知道值时可用remove()删除,且只能删除第一次出现的值,若需删除其他位置的需要循环条件

----------------------------------------------------------------------------------------

sort 排序是对列表永久的更换顺序

sort(reverse=True)

#倒序排列

sorted()

#是对列表元素的临时排序

cars.reverse()

print(cars)

#倒序打印

--------------------------------

squares =[]

for value in range(1,11):

    square = value**2

    squares.append(square)

    print(squares)

_______________________

min(),max(),sum()

squares[value**2 for value in range(1,11)]

print(squares)

-------------------------------------------------------

使用列表的一部分----切片

 

my_foods = ['pizza', 'falafel', 'carrot cake']

 friend_foods = my_foods[:]

整体复制

 ---------------------------------

if语句的使用一般先把特殊条件放在最前边,else后为正常条件

 ----------------------------------------------------------

def get_formatted_name(first_name, last_name, middle_name=''):
  """ 返回整洁的姓名 """
  if middle_name:
  full_name = first_name + ' ' + middle_name + ' ' + last_name
   else:
  full_name = first_name + ' ' + last_name
  return full_name.title()
  musician = get_formatted_name('jimi', 'hendrix')
  print(musician)
musician = get_formatted_name('john', 'hooker', 'lee')
print(musician)

 实参可以选择,

--------------------------------

导入特定的函数

from  a  import   b (b是a中的函数)

from a import  b,c,d(可导入多个a中的函数 使用逗号隔开)

使用  as 给导入的函数定义别名------from pizza import make_pizza as mp

 导入模块中的所有函数可以使用星号*

from  pizza  import  *

定义函数时,形参的等号两边不用空格

def function_name(parameter_0, parameter_1='default value'):

-------------------------------------------------

class ElectricCar(Car):

  """ 电动汽车的独特之处 """
   def __init__(self, make, model, year):
    """ 初始化父类的属性 """
     super().__init__(make, model, year)

继承使用super()

---恢复内容结束---

猜你喜欢

转载自www.cnblogs.com/weilairenlai/p/11724681.html