python总体概要


import math 
math.sin(1)

ctrl+/:整体代码前加#(注释)
”“” “”“跨行注释或跨行字符串

input返回的值为字符串。
四空格缩进
if  elif(满足及执行)
逻辑运算:not and or 按优先级排序(not x > 5  x不大于五)
往列表里添加:
python: shopping_list = ["键盘"]
        shopping_list.append("显示器")  # append 向其中添加元素 remove为删除
        print(shopping_list)

num_list = [1,13,-7,2,96]
print(max(num_list))  #打印列表里的最大值
print(min(num_list))  #打印列表里的最小值
print(sorted(num_list))  #打印排序好的列表

字典
键:值
contacts = {"小明":"00000000","小花":"11111111"}
contacts["小明"]

元组 tuple
example_tuple = ("键盘","键帽")
contacts = {("小明",18):"00000000",("小明",24):"11111111"}
print("小明" in contacts) 返回true 或者 false
del contacts["小明"] #删除键和对应值

for 变量名 in 可迭代对象
range(起始值,结束值)

for i in range(5,10):
print(i)     #i会依次被赋值从5到9的数字
  
定义函数:
def calculate_sector_1():
python:
   def calculate_BMI(weight,height):
      BMI = weight / height ** 2
      if BMI <= 18.5:
          category = "偏瘦"
      elif BMI <=25...

import 语句:
import statistics
print(statistics.median([1,2,3]))  # median 变量名
 
from...import...

类定义属性和方法

类:
class NameOfclass:

class CuteCat:
  def __init__(self):   #定义对象有那些属性
    self.name = "Lambton"
  cat1 = Cutecat("Jojo",2,"橙色")  #可以调用_init_来创建新的对象,把对应属性进行赋值
方法:
    def speak(self):
      print("喵" * self.age)   #方法调用结果,根据属性的不同而改变。

文件:
f = open(”./data.txt“, "r", encoding="utf-8")
print(f.read())
print(f.read(10))
print(f.readline()) # 只会读一行文件内容,并打印。
print(f.readlines())
f.close() # 关闭文件,释放资源
    

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值