zoukankan      html  css  js  c++  java
  • Python3.x基础学习-自己通俗的理解方式(一)

      学任何语言最开始的第一个编程语句就是打印“Hello World!”,

    python 也不例外:

    print("Hello World!")
    

      python是一门解释性、编译性、互动性和面向对象的脚本语言(来源百度百科),为什么这么多语言可以学习,偏偏要学习Python呢?因为语法简单,同样的一个功能,Python可能10行代码搞定,java就可能要100行。本人从事的工作又是测试工作,在功能测试花了大部分时间的情况下,使用自动化来辅助测试,如果再使用其他编程难度高的语言,必然会使自己的工作效率降低,使项目进程得不到有效提升。当然,Python也有很多缺点,比如运行慢,语言不加密等。总之,任何语言都有自己的局限性,选择适合自己的才是最好的。

      写这个博客主要是记录自己的学习经历,如有雷同,一般都不会雷同,哈哈

    1 Python 之数据类型

    跟Java语言类似:

    可分为:1.整型int,浮点型float,布尔型bool,复数型complex,字符串str,列表list[],字典dict{},集合set{},元组tuple()

    1.整型int

    print(123)
    
    # 使用type可以查看数据类型
    print(type(123))
    
    # <class 'int'>
    View Code

    2.浮点型 float,double

    print(123.456)
    print(type(123.456))
    # <class 'float'>
    View Code

    3.布尔型bool

    print(True)
    print(False)
    print(type(True))
    # True
    # # False
    # # <class 'bool'>
    View Code

    4.复数型complex

    print(type(2j+3j))
    # <class 'complex'>
    View Code

    5.字符串str

    print("我爱你")
    print(type("我爱你"))
    # 我爱你
    # <class 'str'>
    View Code

    6.列表list

    x = [1,2,3,'hello']
    print(x)
    print(type(x))
    # [1, 2, 3, 'hello']
    # <class 'list'>
    View Code

    7.元组tuple

    x = (1,2,3,'hello')
    print(x)
    print(type(x))
    # (1, 2, 3, 'hello')
    # <class 'tuple'>
    View Code

    8.字典dict

    x = {"id":1,"name":"小明"}
    print(x)
    print(type(x))
    # {'id': 1, 'name': '小明'}
    # <class 'dict'>
    View Code

    9.集合set

    x = {1,2,3}
    print(x)
    print(type(x))
    # {1, 2, 3}
    # <class 'set'>
    View Code

    2 进制

      从我有限的计算机基础来了解,常用的有 二进制、八进制、十六进制、十进制,而计算机中广泛使用的是二进制

    二进制以0b(0,1)表示,八进制以0o(0,7)表示,十六进制以0x(0,9,a-f)

    2.1 进制转换

    print(bin(10)) 
    print(oct(10)) 
    print(hex(10)) 
    #0b1010
    #0o12
    #0xa
    View Code

    写到最后:还是写不下去了,把自己遇到的坑写一下,这些教程一般的别人都有,而且写得更细,此文不删,以作纪念。

  • 相关阅读:
    手机号码正则表达式
    POJ 3233 Matrix Power Series 矩阵快速幂
    UVA 11468
    UVA 1449
    HDU 2896 病毒侵袭 AC自动机
    HDU 3065 病毒侵袭持续中 AC自动机
    HDU 2222 Keywords Search AC自动机
    POJ 3461 Oulipo KMP模板题
    POJ 1226 Substrings KMP
    UVA 1455 Kingdom 线段树+并查集
  • 原文地址:https://www.cnblogs.com/johnsonbug/p/12556245.html
Copyright © 2011-2022 走看看