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

Python Basics - variables and simple data types

編輯:Python

Catalog

1. Variable naming and use

2. character string

3. add to & Delete blanks

5.str()


1. Variable naming and use

1.1 Variable names can only be Contain letters 、 Numbers and underscores . Variable names can start with letters or underscores , But don't start with numbers .

eg: You can name the variable qqq_0, But it can't be named 0_qqq

1.2 Variable names cannot contain spaces , But you can use an underline to separate the words .

eg: Variable name xxx_xxx feasible , But the variable name xxx xxx Error will be raised .

2. character string

2.1 character string : A string is a series of characters , You can use single quotes / Double quotation marks indicate

2.2 Change the case of words title(), Here's the picture , The running result is Skkd Kkd

name = "skkd kkd"
print("name.title()")

2.3 Change the case of the whole word upper()、lower(), Here's the picture , The running result is SKKD KKD and skkd kkd

name = "skkd kkd"
print("name.upper()")
print("name.lower()")

2.4 Merge strings : Use the plus sign (+ ) To merge strings , Here's the picture , The running result is It is a dog

A = "It is"
B = "a dog"
what = A + " " + B
print(what)

3. add to & Delete blanks

 Add blanks :
1.4.1 Line breaks use \n
1.4.2 Use tabs \t
#1.5.1 Delete the end blank , Usage method rstrip()
a = ' It is fine '
a.rstrip()
#1.5.2 Eliminate the blank at the beginning , Usage method lstrip()
a = ' It is fine '
a.lstrip()
#1.5.3 Eliminate whitespace at the beginning and end , Usage method strip()
a = ' It is fine '
a.strip()

5.str()

Avoid typos , Need to use str()

number = 18
message = "I am" + age + "years old!"
print(message)
# Error will be reported at this time , because number yes int type , So will number convert to str type , Change it to :
number = 18
message = "I am" + str(age) + "years old!"
print(message) 

The learning content of this article refers to 《Python Programming : From introduction to practice 》


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