Python變數和簡單資料型別

2021-10-13 20:56:04 字數 1210 閱讀 2731

學習**

前言:python3

message="hello python world"

print(message)

message="hello python world"

print(message)

message="hello world"

print(message)

"this is a string"

'this is also a string'

name="ling ming"

print(name.title())

2、大寫:字串都大寫

print(name.upper())
3、小寫:字串都小寫

print(name.lower())
1、新建變數拼接

first_name="ling"

last_name="ming"

full_name=first_name+" "+last_name

print(full_name)

2、輸出時拼接

print(first_name+" "+last_name)
name=" python "

print(name.rstrip())

2、刪除開頭的空格

print(name.lstrip())
3、刪除兩頭的空格

print(name.strip())
4、這些刪除空格的函式只是暫時的,要想永久的刪除需要重新定義變數

name=name.strip()
age=18

print(message)

這段**看上去沒有問題,但是執行之後會引發錯誤。

是這樣的,python發現你使用了乙個變數,但是他不知道怎麼解釋,age可能是數字18,也可能是字元1和8。因此需要顯式的指明希望python將這個作為字串。

age=18

print(message)

Python 變數和簡單資料型別

message hello python world print message 輸出結果如下 hello python world 1.2 給相同的變數賦值2次或多次的時候 message hello python world print message message hello python ...

變數和簡單資料型別

指在計算機程式設計中與關聯的識別符號配對的記憶體儲存位置,在使用時含相關型別的值,其值是可以修改的。多個變數賦值 python允許同時為多個變數賦值 a b c 9print a,b,c 9 9 9變數值型別 基本變數型別包括字串 string 數字 numeric 列表 list 元組 tuple...

Python 乾貨 之變數和簡單資料型別

本篇是在本人學習 python 時做的一些筆記,比較簡潔,更是乾貨,請大家笑納 進入 python3 終端 python3。退出 python3 終端 ctrl d ubuntu 或 exit 函式。在 python 終端可執行 python 片段,注意是 片段,不是 py 檔案。在 cmd 命令列...