为了简单起见,我将其分为三个部分:
- 变量声明
- 接受输入并声明输出
- 运算符和表达式
1.变量声明
与 c、cpp 和 java 等其他编程语言不同,您不需要显式声明变量的类型。此功能称为动态输入。
在 C 语言中,
int a = 6;
这里,变量被声明为整数。
但是在Python中,
a = 6
并且变量a可以重新声明为
a = "hello world"
?️注意:
变量名称区分大小写.,因此 a 和 A 被视为不同的变量。
✨ 声明中的特点和规则
- 变量名称必须以字母或下划线 (_) 开头
a = 6 #valid _a = 6 #valid -a = 6 #invalid
- “_”变量存储Python交互模式下最后一个表达式的结果。这可以在 Jupiter Notebook 中看到
a = 5 b = 6 a + b #11 print(_) #11
- 在Python中,一行中可以声明多个变量
a, b, c = 5, 6, 7
- 使用global关键字修改函数内的全局变量
global x def print(): return x #there will be no error
- 与 c 和 cpp 不同,Python 没有内置的方法来声明常量。按照约定,全部大写的变量名被视为常量。
PI=3.14
2.接受输入并声明输出
打印()
print() 函数是一个内置的 Python 函数,用于将输出显示到控制台。
a=10000 print("hello world") #hello world print("hello", "world")#hello world print("hello world",a) #hello world 10000
打印函数中,有两个主要参数。
- sep :它决定打印时如何分隔多个对象。通常预设为“ ”。
- end :定义输出末尾打印的内容。通常预设为“n”。
示例:
print("hello world") print("hi") # hello world # hi
print("hello", "world", sep="-", end = " ") print("hi") # hello-world hi
有关打印的完整文档,请单击此处
✨ Print() 的特点
- 您可以使用转义序列(例如,n 表示换行符,t 表示制表符,__ 表示反斜杠)在打印输出中包含特殊字符。
print("hello\nworld") #hello #world print("hello\tworld") #hello world print("happy\trecking")#happy\trecking
- print() 通常用于调试和跟踪代码执行,因为它提供了一种输出变量值和程序状态的快速方法。
x = 5 y = 10 print(f"x: {x}, y: {y}") # x: 5, y: 10
输入()
Python 中的 input() 函数用于从控制台获取用户输入。
int a = 6;
?️注意:
默认情况下,input() 返回一个字符串,因此如果您需要将输入用作不同类型(例如 int、float),则需要对其进行转换。
a = 6
在即将发布的博客中,我们将深入研究 Python 运算符和条件语句。快乐学习???
以上是掌握 Python 基础知识日的详细内容。更多信息请关注PHP中文网其他相关文章!

ForhandlinglargedatasetsinPython,useNumPyarraysforbetterperformance.1)NumPyarraysarememory-efficientandfasterfornumericaloperations.2)Avoidunnecessarytypeconversions.3)Leveragevectorizationforreducedtimecomplexity.4)Managememoryusagewithefficientdata

Inpython,ListSusedynamicMemoryAllocationWithOver-Asalose,而alenumpyArraySallaySallocateFixedMemory.1)listssallocatemoremoremoremorythanneededinentientary上,respizeTized.2)numpyarsallaysallaysallocateAllocateAllocateAlcocateExactMemoryForements,OfferingPrediCtableSageButlessemageButlesseflextlessibility。

Inpython,YouCansspecthedatatAtatatPeyFelemereModeRernSpant.1)Usenpynernrump.1)Usenpynyp.dloatp.dloatp.ploatm64,formor professisconsiscontrolatatypes。

NumPyisessentialfornumericalcomputinginPythonduetoitsspeed,memoryefficiency,andcomprehensivemathematicalfunctions.1)It'sfastbecauseitperformsoperationsinC.2)NumPyarraysaremorememory-efficientthanPythonlists.3)Itoffersawiderangeofmathematicaloperation

Contiguousmemoryallocationiscrucialforarraysbecauseitallowsforefficientandfastelementaccess.1)Itenablesconstanttimeaccess,O(1),duetodirectaddresscalculation.2)Itimprovescacheefficiencybyallowingmultipleelementfetchespercacheline.3)Itsimplifiesmemorym

SlicingaPythonlistisdoneusingthesyntaxlist[start:stop:step].Here'showitworks:1)Startistheindexofthefirstelementtoinclude.2)Stopistheindexofthefirstelementtoexclude.3)Stepistheincrementbetweenelements.It'susefulforextractingportionsoflistsandcanuseneg

numpyallowsforvariousoperationsonArrays:1)basicarithmeticlikeaddition,减法,乘法和division; 2)evationAperationssuchasmatrixmultiplication; 3)element-wiseOperations wiseOperationswithOutexpliitloops; 4)

Arresinpython,尤其是Throughnumpyandpandas,weessentialFordataAnalysis,offeringSpeedAndeffied.1)NumpyArseNable efflaysenable efficefliceHandlingAtaSetSetSetSetSetSetSetSetSetSetSetsetSetSetSetSetsopplexoperationslikemovingaverages.2)


热AI工具

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

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

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

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

热门文章

热工具

记事本++7.3.1
好用且免费的代码编辑器

SublimeText3 Linux新版
SublimeText3 Linux最新版

VSCode Windows 64位 下载
微软推出的免费、功能强大的一款IDE编辑器

适用于 Eclipse 的 SAP NetWeaver 服务器适配器
将Eclipse与SAP NetWeaver应用服务器集成。

mPDF
mPDF是一个PHP库,可以从UTF-8编码的HTML生成PDF文件。原作者Ian Back编写mPDF以从他的网站上“即时”输出PDF文件,并处理不同的语言。与原始脚本如HTML2FPDF相比,它的速度较慢,并且在使用Unicode字体时生成的文件较大,但支持CSS样式等,并进行了大量增强。支持几乎所有语言,包括RTL(阿拉伯语和希伯来语)和CJK(中日韩)。支持嵌套的块级元素(如P、DIV),