日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

python的类型 变量 数值和字符串

發布時間:2025/6/15 python 18 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python的类型 变量 数值和字符串 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

文件類型一
源代碼
-Python源代碼文件以“py”為擴展名,由Python程序解釋,不需要編譯

[root@lyon-01 ~]# mkdir python
[root@lyon-01 ~]# cd python/
[root@lyon-01 python]# vim 1.py //寫一個代碼

#! /usr/bin/python

print 'hellow world'

[root@lyon-01 python]# python 1.py //執行
hellow world

文件類型二
字節代碼
-Python源代碼文件經編譯后,生成的擴展名為“pyc”的文件
-編譯方法:

import py_compile
py_compile.compile('hello.py')

[root@lyon-01 python]# vim 2.py

#! /usr/bin/python

import py_compile
py_compile.compile('./1.py')
[root@lyon-01 python]# python 2.py
[root@lyon-01 python]# ls
1.py 1.pyc 2.py
[root@lyon-01 python]# file 1.pyc
1.pyc: python 2.7 byte-compiled
[root@lyon-01 python]# cat 1.py
#! /usr/bin/python

print 'hellow world'
[root@lyon-01 python]# cat 1.pyc

?顁@s dGHdS(s
hellow worldN((((s./1.py<module>s //二進制的亂碼文件
[root@lyon-01 python]#
[root@lyon-01 python]# python 1.pyc //用Python查看
hellow world
[root@lyon-01 python]#
-優化代碼
-經過優化的源碼文件,擴展名為“pyo”
-Python -O -m py_compile hello.py

[root@lyon-01 python]# python -O -m py_compile 1.py
[root@lyon-01 python]# ls
1.py 1.pyc 1.pyo 2.py
[root@lyon-01 python]# python 1.pyo
hellow world
[root@lyon-01 python]#

python 的變量
--變量是計算機內存中的一塊區域,變量可以存儲規定范圍內的值,而且值可以改變
--Python下的變量是對一個數據的引用
--變量的命名 由字母 數字 下劃線組成 不能以數字開頭 不可以使用關鍵字
--變量的賦值 是變量的聲明和定義的過程 a = 1 id(a)

[root@lyon-01 python]# vim 3.py
#! /usr/bin/python
num1 = input("please a number: ")
num2 = input("please a number: ")
print num1 + num2
print num1 - num2
print num1 num2
print num1 / num2
[root@lyon-01 python]# python 3.py
please a number: 5
please a number: 3
8
2
15
1
[root@lyon-01 python]# vim 3.py
#! /usr/bin/python
num1 = input("please a number: ")
num2 = input("please a number: ")
print "%s + %s = %s" % (num1, num2, num1+num2)
print "%s - %s = %s" % (num1, num2, num1-num2)
print "%s %s = %s" % (num1, num2, num1num2)
print "%s / %s = %s" % (num1, num2, num1/num2)
[root@lyon-01 python]# python 3.py
please a number: 7
please a number: 3
7 + 3 = 10
7 - 3 = 4
7 3 = 21
7 / 3 = 2

python的數據類型
案例 123和‘123’一樣嗎?
123 代表數值
‘123’代表字符串
還有 列表 元祖 字典
數值類型
長整型

In [9]: a = 12999999999999999999999
In [10]: a
Out[10]: 12999999999999999999999L
In [11]: type (a)
Out[11]: long
也可以把小的數值長整型
In [12]: a = 100l
In [13]: type (a)
Out[13]: long

浮點型 例如 0.0 12.0 -18.8 3e+7
復數型
換行符

In [23]: a = "hello\nworld"
In [24]: print a
hello
world

轉載于:https://blog.51cto.com/13358833/2052577

總結

以上是生活随笔為你收集整理的python的类型 变量 数值和字符串的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。