Python入门基础知识(零基础篇)

        大家好,这是我Python 学习之旅的第一篇博客。作为一名 Python 初学者,我将把我最近学习的一些基础知识与大家交流,希望能为大家入门 Python 提供一些帮助。​

学习详情:

        打印语句​

        最基础的就是使用 print函数来输出内容。无论是用单引号还是双引号括起来的字符串都能正常打印。例如:

print("hello world")
print('hello world!')

        如果要在同一行输出多个内容,可以用加号来拼接字符串:​

print("你好"+"G"+"!")​

       还可以使用 \n 实现换行或者使用三引号:

print("你好\n中国")

        变量与赋值​

        变量是存储数据的容器。在 Python 中,变量名不能以数字开头,也不能包含空格,只能由字母、数字和下划线组成。例如:​

abc = 456
print(abc)

       字符串连接

       字符串可以进行连接操作,还可以通过索引来获取特定字符。例如:

aaa = "hello world"
print(aaa[3])  # 输出 'l'

        要获取字符串的最后一个字符,可以用 len函数获取长度,再减 1 作为索引:

print(aaa[len(aaa)-1])

        数据类型​Python 中有多种数据类型:

​整数 (int)​ :如 6、-32​

浮点数 (float)​ :如 6.0、10.07

​字符串 (str)​ :如 "hello"、"学习!"

​布尔类型 (bool)​ :True 和 False​

空值类型 (NoneType)​ :None​

       可以使用 type函数来判断变量的数据类型:

print(type(123))  # 输出 <class 'int'>
print(type(1.9))  # 输出 <class 'float'>
print(type("hello world!"))  # 输出 <class 'str'>
print(type(True))  # 输出 <class 'bool'>
print(type(None))  # 输出 <class 'NoneType'>​

        以上就是我目前学习 Python 的一些基础知识。通过这些简单的代码示例,我逐渐理解了 Python 的基本入门知识。希望这篇博客能对同样在学习 Python 的初学者有所帮助!如果你有任何问题或建议,请随时在评论区留言,我们一起交流学习。

附加:

print("hello world")
print("学习!学习!")
print("666")
#单双引号都可行
print('hello world!')
#\n换行,\:反斜杠转义符
print("你好\n中国")
print("你好"+"G"+"!")
#"内加了空格"
print("你好"+" G")
#外双内单/内双外单都行
print('he said "good"')
#\后跟随的"或者'被打印出来
print("let\'s go")
print("he said \"let\'s go!\"")
print('print("print")')
#赋值,变量名不能数字开头!!!不能有空格!!!由文字数字下划线_组成
abc=456
print(abc)
#存储:把456存储
bcd=abc
print(bcd)
"""
三引号注释
"""
abc=258
print(abc)
print(bcd)
用户10086=258
print(用户10086)
print(2+3)
ye=6
print(ye+6)
ye=7
print(ye+9)
#赋值字符串str
kkk="吃了吗?"
print(kkk+"G")
mmm="没吃"
kkk=mmm
print(kkk+",好饿呀!")
#"""_"""_'''_'''回车自动换行
print("""人生天地间,
忽如远行客.""")
#数学运算
print(6+1+2+4+1/2)
print(6*7)
print(12/6)
print(12/2**2)
print(2**3)
#len判断字符串长度
print(len('hello'))
#[3]索引第一个为0
print("hello"[3])
aaa="hello world"
print(len(aaa))
#得到字符串最后一个,总为11,因为从0开始计算,所以最后一个为10.
print(aaa[10])
print(aaa[len(aaa)-1])
#判断数据类型,type函数,整数
print(type(123))
#浮点数
print(type(1.9))
#字符串
bbb="hello world!"
print(type(bbb))
#布尔类型
print(type(True))
print(type(False))
#空值类型None type
print(type(None))
#"""_"""为注释一种,control+/数列快捷全加#
"""
数据类型
Hello哟字符串 str
6 -32整数 int
6.0 10.07浮点数 float
True False布尔类型 bool
None空值类型 NoneType
包括字符串、整数、浮点数、布尔类型、空值类型
"""

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值