zoukankan      html  css  js  c++  java
  • python语法相关---1、

    python语法相关---1、

    一、总结

    一句话总结:

    不要务虚名而致实祸

    1、python中列表、元组、字典、集合的关系?

    列表就相当于其它语言中的数组:用中括号[]表示
    元组与列表类似,不同之处在于元组的元素不能修改:用原括号()表示
    字典就是其它语言中的键值对:用大括号{}表示
    集合就是其它语言中的集合:集合(set)是一个无序的不重复元素序列。

    2、python 赋值号左右两边对等位置赋值?

    a, b = 0, 1
    a, b = 0, 1
    while b < 10:
        print(b)
        a, b = b, a + b

    3、python基本数据类型?

    数字(int、float、complex复数、bool)、字符串、复杂数据类型(列表、元组、字典、集合)

    4、查看变量类型?

    type方法:print(type(a))

    5、python算术运算符中的注意点?

    **表示指数,比如7**3 表示7的3次方
    //表示整除 7//3=2

    6、python中的逻辑运算符?

    and or not 注意是英文而不是符号

    7、字符串输入输出?

    input输入:name=input("请输入你的名字")
    print输出:print("我的名字是%s,年龄%d岁"%(name,age))
    #input输入都是字符串类型的
    name=input("请输入你的名字")
    age=18
    print("我的名字是%s,年龄%d岁"%(name,age))
    print("我的名字是{}".format(name))

    8、每隔一个空格输出?

    print(item,end=' ')
    str="python"
    for i in str:
        print(i,end=' ')
        pass
    输出:p y t h o n 

    9、强制转换?

    age=int(input("请输入你的年龄"))

    10、选择结构?

    if 条件表达式  elif 条件表达式  else:
    age=int(input("请输入你的年纪"))
    if age>=10:
        print("年纪合格")
    elif age>=5:
        print("年纪尚小")
    else:
        print("还是婴儿")

    二、内容在总结中

    博客对应课程的视频位置:

     
  • 相关阅读:
    LC.225. Implement Stack using Queues(using two queues)
    LC.232. Implement Queue using Stacks(use two stacks)
    sort numbers with two stacks(many duplicates)
    LC.154. Find Minimum in Rotated Sorted Array II
    LC.81. Search in Rotated Sorted Array II
    LC.35.Search Insert Position
    前后端分离:(一)
    Redis基本使用(一)
    GIT篇章(二)
    GIT篇章(一)
  • 原文地址:https://www.cnblogs.com/Renyi-Fan/p/13154163.html
Copyright © 2011-2022 走看看