大家好,
今天我们要学习Python变量。
变量
- 常见变量会保留一些值,如 str、int 等
- Python 没有使用任何命令来声明变量,当值 3. 首先分配时,变量被创建并且区分大小写。
- 变量不需要声明为任何特定类型,甚至可以在设置后更改类型。
a=1 # variable as int b="aravin" # variable as string x=5 # First assign the int value to X x='aravin' # Later assign the str value to X print(x) # o/p aravin, recently assign value to use same variable.
区分大小写
a=100 A='India' # a will not overwrite to A both are diff. print(a) print(A)
获取变量类型
var=100 mvar='Hello' print(type(var))
创建变量的规则
- 变量名称应以字符或下划线字符开头。
- 不应以数字开头。
- 不能是任何Python关键字。
例如:
正确名称:
my_variable_name = "Aravin" #蛇类型
myVariableName = "Aravin" #骆驼类型
MyVariableName = "Aravin" #Pascal 类型
myvarname =“阿拉文”
_myvarname =“阿拉文”
myvar_name = "阿拉文"
myvar21 =“阿拉文”
不正确的名称:
2myVar =“你好”
my-var =“你好”
我的 var =“你好”
将多个值分配给多个变量
a,b,c = 5,"aravin","DB"
一个值到多个变量
a = b = c = "Apple"
解压集合
myVar = ["var1","var2","var3"] a,b,c = myVar print(myVar) print(b)
全局变量
- 在称为全局变量的函数外部创建或使用 global 关键字创建。
- 全局变量可以被函数内部和外部的每个人使用
例如:
在函数外部创建
a = "python" def myfunc(): print("Hello " + a) myfunc()
函数内部创建的变量,与全局同名
a = "python" def myfunc(): a = "python" print("Hai " + a) myfunc() print("Hello " + a)
在函数内使用 global 关键字创建全局变量
def myfunc(): global a a = "python" myfunc() print("Hello " + a)
更改函数内的全局变量值
a = "python" def myfunc(): global a a = "Python" myfunc() print("Hai " + x)
以上是Python:变量的详细内容。更多信息请关注PHP中文网其他相关文章!

pythonlistscanStoryDatatepe,ArrayModulearRaysStoreOneType,and numpyArraySareSareAraysareSareAraysareSareComputations.1)列出sareversArversAtileButlessMemory-Felide.2)arraymoduleareareMogeMogeNareSaremogeNormogeNoreSoustAta.3)

WhenyouattempttostoreavalueofthewrongdatatypeinaPythonarray,you'llencounteraTypeError.Thisisduetothearraymodule'sstricttypeenforcement,whichrequiresallelementstobeofthesametypeasspecifiedbythetypecode.Forperformancereasons,arraysaremoreefficientthanl

pythonlistsarepartofthestAndArdLibrary,herilearRaysarenot.listsarebuilt-In,多功能,和Rused ForStoringCollections,而EasaraySaraySaraySaraysaraySaraySaraysaraySaraysarrayModuleandleandleandlesscommonlyusedDduetolimitedFunctionalityFunctionalityFunctionality。

ThescriptisrunningwiththewrongPythonversionduetoincorrectdefaultinterpretersettings.Tofixthis:1)CheckthedefaultPythonversionusingpython--versionorpython3--version.2)Usevirtualenvironmentsbycreatingonewithpython3.9-mvenvmyenv,activatingit,andverifying

Pythonarrayssupportvariousoperations:1)Slicingextractssubsets,2)Appending/Extendingaddselements,3)Insertingplaceselementsatspecificpositions,4)Removingdeleteselements,5)Sorting/Reversingchangesorder,and6)Listcomprehensionscreatenewlistsbasedonexistin

NumPyarraysareessentialforapplicationsrequiringefficientnumericalcomputationsanddatamanipulation.Theyarecrucialindatascience,machinelearning,physics,engineering,andfinanceduetotheirabilitytohandlelarge-scaledataefficiently.Forexample,infinancialanaly

useanArray.ArarayoveralistinpythonwhendeAlingwithHomeSdata,performance-Caliticalcode,orinterFacingWithCcccode.1)同质性data:arrayssavememorywithtypedelements.2)绩效code-performance-clitionalcode-clitadialcode-critical-clitical-clitical-clitical-clitaine code:araysofferferbetterperperperformenterperformanceformanceformancefornalumericalicalialical.3)

不,notalllistoperationsareSupportedByArrays,andviceversa.1)arraysdonotsupportdynamicoperationslikeappendorinsertwithoutresizing,wheremactssperformance.2)listssdonotguaranteeconeeconeconstanttanttanttanttanttanttanttanttimecomplecomecomecomplecomecomecomecomecomecomplecomectaccesslikearrikearraysodo。


热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

Video Face Swap
使用我们完全免费的人工智能换脸工具轻松在任何视频中换脸!

热门文章

热工具

Atom编辑器mac版下载
最流行的的开源编辑器

SecLists
SecLists是最终安全测试人员的伙伴。它是一个包含各种类型列表的集合,这些列表在安全评估过程中经常使用,都在一个地方。SecLists通过方便地提供安全测试人员可能需要的所有列表,帮助提高安全测试的效率和生产力。列表类型包括用户名、密码、URL、模糊测试有效载荷、敏感数据模式、Web shell等等。测试人员只需将此存储库拉到新的测试机上,他就可以访问到所需的每种类型的列表。

Dreamweaver CS6
视觉化网页开发工具

SublimeText3汉化版
中文版,非常好用

DVWA
Damn Vulnerable Web App (DVWA) 是一个PHP/MySQL的Web应用程序,非常容易受到攻击。它的主要目标是成为安全专业人员在合法环境中测试自己的技能和工具的辅助工具,帮助Web开发人员更好地理解保护Web应用程序的过程,并帮助教师/学生在课堂环境中教授/学习Web应用程序安全。DVWA的目标是通过简单直接的界面练习一些最常见的Web漏洞,难度各不相同。请注意,该软件中