zoukankan      html  css  js  c++  java
  • Python基础语法

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

    数据类型

    基本数据类型:

     

    a = 18
    b = str(a)
    c = int(b)
    d = float(c)
    print(type(a), type(b),type(c), type(d))
    print(a, b, c, d)

    输出结果:

    String常用的操作:

     

    a = 'Hello'
    b = 'Python'
    print(a+b)
    print(b*3)
    print(a[4])
    print(b[2:5])
    print('o' in a)
    print('g' not in b)

     list的常用操作:

    a = ['c++', 'python', 100, 'java', 99.9]
    a.append('go')
    print(a)
    b = ['in', 'not']
    a.extend(b)
    print(a)
    a.remove('not')
    print(a)
    del a[1]
    print(a)
    a.insert(1,'insert')
    print(a)
    a.clear()

     list常用函数:

    修改字典的值:

     

    a = {'Dh':'1', 'sen':'1', 'ni':1}
    print(a)
    a['Dh']='d'
    print(a)
    del a['ni']
    print(a)
    del a

    控制语句

    if条件语句

    for循环语句

    i = 0;
    for letter in 'python':
        i = i+1
        print(letter, i)
    fruits = ['apple', 'orange', 'banane']
    for fruit in fruits:
        print(fruit)
    for index in range(len(fruits)):
        print("当前水果:", fruits[index])

    while语句

    i = 0
    while i<10:
        if i%2 == 0:
            print(i,"可以被2整除")
        elif i%3 == 0:
            print(i, "可以被3整除")
        else:
            print(i, "你最牛逼")
        i = i+1

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

  • 相关阅读:
    126
    125
    124
    123
    122
    121
    120
    119
    洛谷 P5407 【[THUPC2019]历史行程】
    济南清北学堂七日游
  • 原文地址:https://www.cnblogs.com/dong973711/p/11706882.html
Copyright © 2011-2022 走看看