Python foundation -- basic data type & STR operation

He Xiaoqing 2021-01-23 21:35:08
python foundation basic data type


  1. Overview of basic number types (7 Kind of )

    • 10203 123 3340 int +- * / wait
    • ' Did you eat today ?' str Store a small amount of data ,+ *int section , Other methods of operation
    • True False bool Judge true or false
    • [12, True, 'a1', [1,2,3 ]] list Store a lot of data .
    • (12, True, 'a1', [1,2,3 ]) tuple Store a lot of data , You can't change the elements inside .
    • {'name': ' Zhang San '} dict Store a lot of correlated data , Very fast query speed .
    • set intersection , Union difference set ...
  2. int

    • Decimal binary conversion

    •  '''
      Binary to decimal
      0001 1010 ------> ? 26
      '''
      b = 1 * 2**4 + 1 * 2**3 + 0 * 2**2 + 1 * 2**1 + 0 * 2**0
      # print(b) # 26
      '''
      42 -----> 0010 1010
      '''
      
    • bit_lenth The effective length of decimal to binary

      # bit_lenth Effective binary length
      i = 4
      print(i.bit_length()) # 3
      i = 5
      print(i.bit_length()) # 3
      i = 42
      print(i.bit_length()) # 4
      
  3. bool

    • bool str int The transition between the three

      # bool str int
      # bool <---> int
      '''
      True 1 False 0
      Non zero means True 0 yes False
      '''
      # str <---> int ***
      '''
      s1 = 10 int(s1) : It has to be digital
      i = 100 str(i)
      '''
      # str bool ***
      # It's not empty True
      s1 = ' '
      print(bool(s1)) # True Spaces are also characters
      s1 = '' # An empty string
      print(bool(s1)) # False
      # bool ---> str meaningless
      print(str(True))
      
    • application :

      s = input(' Input content ')
      if s:
      print(' There are content ')
      else:
      print(' No input ')
      
  4. str

    • Index slice step size

      s1 = 'python The whole stack 22 period '
      # Index strings , The sliced data is of string type .
      # Value by index
      # There is an order from left to right , Subscript , Indexes .
      s2 = s1[0]
      print(s2,type(s2))
      s3 = s1[2]
      print(s3)
      s4 = s1[-1]
      print(s4)
      # Value according to slice .
      # I don't care
      s5 = s1[0:6]
      s5 = s1[:6]
      print(s5)
      s6 = s1[6:]
      print(s6)
      # Slice step size
      s7 = s1[:5:2]
      print(s7)
      print(s1[:])
      # In reverse order :
      s8 = s1[-1:-6:-1]
      print(s8)
      # By index :s1[index]
      # According to the slice : s1[start_index: end_index+1]
      # According to the slice step size : s1[start_index: end_index+1:2]
      # Reverse according to slice step size : s1[start_index: end_index One bit later :2]
      # Thinking questions : All in reverse order ?
      
    • Exercises

      2. There are strings s = "123a4b5c"
      Through to s Slice to form a new string s1,s1 = "123"
      Through to s Slice to form a new string s2,s2 = "a4b"
      Through to s Slice to form a new string s3,s3 = "1345"
      Through to s Slice into strings s4,s4 = "2ab"
      Through to s Slice into strings s5,s5 = "c"
      Through to s Slice into strings s6,s6 = "ba2"
      
    • Common operation methods

      # upper lower
      # s1 = s.upper()
      # # s1 = s.lower()
      # print(s1,type(s1))
      # application :
      username = input(' user name ')
      password = input(' password ')
      code = 'QweA'
      print(code)
      your_code = input(' Please enter the verification code : Case insensitive ')
      if your_code.upper() == code.upper():
      if username == ' The white ' and password == '123':
      print(' Login successful ')
      else:
      print(' Wrong username and password ')
      else:
      print(' Verification code error ')
      
版权声明
本文为[He Xiaoqing]所创,转载请带上原文链接,感谢
https://pythonmana.com/2021/01/20210123213441828T.html

  1. Experience of learning Python
  2. python7、8章
  3. Chapter 7 and 8 of Python
  4. python bool和str转换
  5. python——循环(for循环、while循环)及练习
  6. python变量和常量命名、注释规范
  7. python自定义异常捕获异常处理异常
  8. python 类型转换与数值操作
  9. python 元组(tuple)和列表(list)区别
  10. 解决python tkinter 与 sleep 延迟问题
  11. python字符串截取操作
  12. Python bool and STR conversion
  13. Python -- loop (for loop, while loop) and Practice
  14. Specification for naming and annotating variables and constants in Python
  15. Python custom exception capture exception handling exception
  16. Python type conversion and numerical operation
  17. The difference between tuple and list in Python
  18. Solve the delay problem of Python Tkinter and sleep
  19. Python string interception operation
  20. Python 100天速成中文教程,GitHub标星7700
  21. Python 100 day quick Chinese course, GitHub standard star 7700
  22. 以我的親身經歷,聊聊學python的流程,同時推薦學python的書
  23. With my own experience, I'd like to talk about the process of learning Python and recommend books for learning python
  24. python爬虫获取起点中文网人气排行Top100(快速入门,新手必备!)
  25. Python crawler to get the starting point of Chinese network popularity ranking Top100 (quick start, novice necessary!)
  26. 【Python常用包】itertools
  27. Itertools
  28. (国内首发)最新python初学者上手练习
  29. (国内首发)最新python初学者上手练习
  30. (first in China) the latest practice for beginners of Python
  31. (first in China) the latest practice for beginners of Python
  32. (数据科学学习手札104)Python+Dash快速web应用开发——回调交互篇(上)
  33. (data science learning notes 104) Python + dash rapid web application development -- callback interaction (Part 1)
  34. (数据科学学习手札104)Python+Dash快速web应用开发——回调交互篇(上)
  35. (data science learning notes 104) Python + dash rapid web application development -- callback interaction (Part 1)
  36. (資料科學學習手札104)Python+Dash快速web應用開發——回撥互動篇(上)
  37. (materials science learning notes 104) Python + dash rapid web application development -- callback interaction (Part 1)
  38. Python OpenCV 图片高斯模糊
  39. Python OpenCV image Gaussian blur
  40. Stargan V2: converse image synthesis for multiple domains reading notes and Python code analysis
  41. 零基础入门Python:基本命令、函数、数据结构
  42. Python: basic commands, functions and data structures
  43. 毫无基础的人如何入门Python?从入门到进阶三份教程,拿走不谢
  44. How can a person without foundation get into Python? From the introduction to the advanced three tutorials, take away
  45. Python设计模式面向对象编程
  46. Python design pattern object oriented programming
  47. Python设计模式面向对象编程
  48. Python design pattern object oriented programming
  49. 怎么样描述你的数据——用python做描述性分析
  50. GitHub上3k+star的python爬虫库你了解吗?详解MechanicalSoup爬虫库
  51. python数据分析——在python中实现线性回归
  52. 疫情来袭,30分钟学会用python开发部署疫情可视化网站
  53. How to describe your data
  54. Do you know the python crawler Library of 3K + star on GitHub? Mechanical soup crawler Library
  55. Python data analysis -- realizing linear regression in Python
  56. When the epidemic strikes, learn to develop and deploy the visualization website of epidemic situation with Python in 30 minutes
  57. 手机上利用python进行数据分析——创建自己的远程jupyter notebook
  58. python数据类型的强制转换
  59. Using Python for data analysis on mobile phones -- creating your own remote jupyter notebook
  60. Mandatory conversion of Python data type