程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Fundamentals of python (I)

編輯:Python

Catalog

  • Small reminder ( summary )
      • Write it at the front
  • String character string
  • import And from...impprt
    • difference import and from...import *
  • Representation of functions
  • Python Connect MySQL database

Small reminder ( summary )

Write it at the front

String character string

python The use of single and double quotation marks in is exactly the same

Use three quotes (’’' or """) You can specify a multiline string

Escape character ‘’, You can enter special characters by escaping characters , Use r You can keep the backslash from escaping .. Such as r"this is a line with \n" be \n Will be displayed , It's not a new line .

String can be used + Operators join together , use * Operator repetition .

The syntax format of string truncation is as follows : Variable [ Header subscript : Tail subscript : step ]

str1='rootbook'
print(str1)
print(str1[0:-1])
# Natural numbers are counted from left to right , Negative numbers are counted from right to left 
print(str1[0])# Output the first character 
print(str1[2:])# Output all characters after the third 
print(str1[[1:5:2])# The output starts from the second number to the fifth number and the retrieval interval is 2
print(str1*2)# Output string twice 
print(str1+' Hello ')

import And from…impprt

stay python use import perhaps from…import To import the corresponding module .

The whole module (somemodule) Import , The format is : import somemodule

Import a function from a module , The format is : from somemodule import somefunction

Import multiple functions from a module , The format is : from somemodule import firstfunc, secondfunc, thirdfunc

Import all functions in a module into , The format is : from somemodule import *

difference import and from…import *

import After import , When using functions in this module , Module name qualification required .

*from…import After import , There is no need to restrict the use of these functions

Representation of functions

def show_num(num):
# The body of the function 
print(num)
# Call function 
show_num(100)
def show_num(num):
# The body of the function 
print(num*3)
# Call function 
show_num(100)

Python Connect MySQL database

#select * from comment order

  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved