最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Python基礎(chǔ)知識(shí)+結(jié)構(gòu)+數(shù)據(jù)類型

 更新時(shí)間:2022年05月07日 17:22:07   作者:螞蟻ailing  
這篇文章主要介紹了Python基礎(chǔ)知識(shí)+結(jié)構(gòu)+數(shù)據(jù)類型,文章基于python基礎(chǔ)知識(shí)圍繞主題展開詳細(xì)內(nèi)容介紹,具有一定的參考價(jià)值,需要的小伙伴可以參考一下

前言

今天給大家分享一些Python的基礎(chǔ)知識(shí),想要蓋好大房子,不把地基打扎實(shí)打牢怎么行呢?所以,今天咱們就來學(xué)習(xí)基礎(chǔ)知識(shí),

這樣后期學(xué)習(xí)Python的時(shí)候才能更容易掌握,更輕松的學(xué)會(huì)Python的使用。

一、編程基礎(chǔ)

1.基本的輸入輸出

print("Hello World");
Name = input('請(qǐng)輸入您的姓名:');
print(Name);
D:\工作空間\Python\venv\Scripts\python.exe D:/工作空間/Python/main.py
Hello World
請(qǐng)輸入您的姓名:Alice
Alice
進(jìn)程已結(jié)束,退出代碼0

2.變量

print("-------------輸出語句-------------");
message="Hello Python world";
print(message);
print("-------------首字母大寫-------------");
name="ada lovelace";
print(name.title());
print("-------------大小寫-------------");
print(name.upper());
print(name.lower());
print("-------------拼接字符串-------------");
first_name = "ada"
last_name = "lovelace"
full_name = first_name + " " + last_name
print(full_name);
print("-------------添加空白-------------");
print("\tPython");
print("Languages:\nPython\nC\nJavaScript");
print("-------------刪除空白-------------");
print("Hello ".rstrip());
print("-------------運(yùn)算-------------");
print(2+3);
print(3-2);
print(2*3);
print(3/2);
print(3**2);
print(3**3);
print(10**6);
print(0.1+0.1);
print(0.2+0.2);
print("------------注釋-------------");
# 測(cè)試注釋

-------------輸出語句-------------
Hello Python world
-------------首字母大寫-------------
Ada Lovelace
-------------大小寫-------------
ADA LOVELACE
ada lovelace
-------------拼接字符串-------------
ada lovelace
-------------添加空白-------------
    Python
Languages:
Python
C
JavaScript
-------------刪除空白-------------
Hello
-------------運(yùn)算-------------
5
1
6
1.5
9
27
1000000
0.2
0.4
------------注釋-------------

Process finished with exit code 0

3.基本運(yùn)算符

print("-----------------算數(shù)運(yùn)算符-----------------");
#+ 加,兩個(gè)對(duì)象相加
#- 減,得到負(fù)數(shù)或是一個(gè)數(shù)減去另一個(gè)數(shù)
#* 乘,兩個(gè)數(shù)相乘或是返回一個(gè)被重復(fù)若干次的字符串
#x/y 除,x 除以 y
#% 取模,返回除法的余數(shù)
#// 取整除,返回商的整數(shù)部分
#x**y 冪
print(12+13);
print(12-13);
print(12*13);
print(12/13);
print(12/13);
print(12%13);
print(12//13);
print(12**13);
print("-----------------比較運(yùn)算符-----------------");
#== 等于,比較對(duì)象是否相等 (a == b)返回 False
#!= 不等于,比較兩個(gè)對(duì)象是否不相等 (a != b)返回 True
#<> 不等于,比較兩個(gè)對(duì)象是否不相等 (a <> b)返回 True。這個(gè)運(yùn)算符類似 !=
#x > y 大于,返回 x 是否大于 y (a > b)返回 False
#x < y小于,返回 x 是否小于 y。所有比較運(yùn)算符返回 1表示真,返回 0 表示假。這分別與特殊的變量 True 和 False 等價(jià)。注意這些變量名的大小寫(a < b)返回 True
#x >= y 大于等于,返回 x 是否大于等于 y (a >= b)返回 False
#x <= y 小于等于,返回 x 是否小于等于 y (a <= b)返回 True
print(12>13);
print(12>=13);
print(12<13);
print(12<=13);
print(12!=13);
print(12==13);
print("-----------------賦值運(yùn)算符-----------------");
#= 簡(jiǎn)單的賦值運(yùn)算符 c = a + b 將 a + b 的運(yùn)算結(jié)果賦值為 c
#+= 加法賦值運(yùn)算符 c += a 等效于 c = c + a
#-= 減法賦值運(yùn)算符 c-= a 等效于 c = c-a
#*= 乘法賦值運(yùn)算符 c *= a 等效于 c = c * a
#/= 除法賦值運(yùn)算符 c /= a 等效于 c = c / a
#%= 取模賦值運(yùn)算符 c %= a 等效于 c = c % a
#**= 冪賦值運(yùn)算符 c **= a 等效于 c = c ** a
#//= 取整除賦值運(yùn)算符 c //= a 等效于 c = c // a
a=21;
b=10;
c=0;
c+=a;
print(c);
c*=b;
print(c);
c/=a;
print(c);
c-=b;
print(c);
c=2;
c%=a;
print(c);
c**=a;
print(c);
c//=a;
print(c);
print("-----------------位運(yùn)算符-----------------");
#& 按位與運(yùn)算符 (a & b)輸出結(jié)果 12,二進(jìn)制解釋:0000 1100
#| 按位或運(yùn)算符 (a | b)輸出結(jié)果 61,二進(jìn)制解釋:0011 1101
#^ 按位異或運(yùn)算符 (a ^ b)輸出結(jié)果 49,二進(jìn)制解釋:0011 0001
#~ 按位取反運(yùn)算符
#(~a)輸出結(jié)果?61,二進(jìn)制解釋:1100 0011,
#在一個(gè)有符號(hào)二進(jìn)制數(shù)的補(bǔ)碼形式
#<< 左移動(dòng)運(yùn)算符 a << 2 輸出結(jié)果 240,二進(jìn)制解釋:1111 0000
#>> 右移動(dòng)運(yùn)算符 a >> 2 輸出結(jié)果 15,二進(jìn)制解釋:0000 1111
a=60;
b=13;
c=0;
c=a&b;
print(c);
c=a|b;
print(c);
c=a^b;
print(c);
c=~a;
print(c);
c=a<<2;
print(c);
c=a>>2;
print(c);
print("-----------------邏輯運(yùn)算符-----------------");
#x and y 布爾“與”,如果 x 為 False,x and y 返回 False,否則它返回 y 的計(jì)算值
#x or y 布爾“或”,如果 x 是 True,它返回 True,否則它返回 y 的計(jì)算值
#x not y 布爾“非”,如果 x 為 True,返回 False。如果 x 為 False,它返回 True
a=10;
b=20;
print(a and b);
a=0;
print(a and b);

D:\工作空間\Python\venv\Scripts\python.exe D:/工作空間/Python/main.py
-----------------算數(shù)運(yùn)算符-----------------
25
-1
156
0.9230769230769231
0.9230769230769231
12
0
106993205379072
-----------------比較運(yùn)算符-----------------
False
False
True
True
True
False
-----------------賦值運(yùn)算符-----------------
21
210
10.0
0.0
2
2097152
99864
-----------------位運(yùn)算符-----------------
12
61
49
-61
240
15
進(jìn)程已結(jié)束,退出代碼0

二、控制流程

1.選擇結(jié)構(gòu)

print("-------------檢查是否相等-------------");
car='bmw';
print(car=='bmw');
print(car=='audi');
print(car=='BMW');
print(car.upper()=='BMW');
age=18;
print(age==18);
print(age>=18);
print(age<=18);
print(age>18);
print(age<18);
age_0 = 22;
age_1 = 18;
print(age_0 >= 21 and age_1 >= 21);
print(age_0 >= 21 or age_1 >= 21);
print("-------------if語句-------------");
age = 19
if age >= 18:
    print("You are old enough to vote!");
    
    age=17
    if age>=18:
        print("You are old enough to vote!");
    else:
        print("Sorry you are too young");
        age = 12
        if age < 4:
            print("Your admission cost is $0.")
        elif age < 18:
            print("Your admission cost is $5.")
        else:
            print("Your admission cost is $10.")
            age = 12
            if age < 4:
                price = 0
            elif age < 18:
                price = 5
            elif age < 65:
                price = 10
            elif age >= 65:
                price = 5
print("Your admission cost is $" + str(price) + ".")
-------------檢查是否相等-------------
True
False
False
True
True
True
True
False
False
False
True
-------------if語句-------------
You are old enough to vote!
Sorry you are too young
Your admission cost is $5.
Your admission cost is $5.
Process finished with exit code 0

2.循環(huán)結(jié)構(gòu)

print("-------------函數(shù)input()的工作原理-------------");
message = input("Tell me something, and I will repeat it back to you: ")
print(message)
print("-------------編寫清晰的程序-------------");
name=input("Please enter your name:");
print("Hello,"+name+"!");
print("-------------求模運(yùn)算符-------------");
print(4%3);
print("-------------while循環(huán)-------------");
current_number = 1
while current_number <= 5:
    print(current_number)
    current_number += 1
print("-------------讓用戶選擇何時(shí)退出-------------");
prompt = "\nTell me something, and I will repeat it back to you:"
prompt += "\nEnter 'quit' to end the program. "
message = ""
while message != 'quit':
    message = input(prompt)
    print(message)
print("-------------break語句-------------");
prompt = "\nPlease enter the name of a city you have visited:"
prompt += "\n(Enter 'quit' when you are finished.) "
while True:
    city = input(prompt)
    if city == 'quit':
        break
    else:
        print("I'd love to go to " + city.title() + "!")
-------------函數(shù)input()的工作原理-------------
Tell me something, and I will repeat it back to you: Hello World
Hello World
-------------編寫清晰的程序-------------
Please enter your name:Alice
Hello,Alice!
-------------求模運(yùn)算符-------------
1
-------------while循環(huán)-------------
1
2
3
4
5
-------------讓用戶選擇何時(shí)退出-------------

Tell me something, and I will repeat it back to you:
Enter 'quit' to end the program. Hello World
Hello World

Tell me something, and I will repeat it back to you:
Enter 'quit' to end the program. quit
quit
-------------break語句-------------

Please enter the name of a city you have visited:
(Enter 'quit' when you are finished.) ShangHai
I'd love to go to Shanghai!

Please enter the name of a city you have visited:
(Enter 'quit' when you are finished.) quit

Process finished with exit code 0

三、數(shù)據(jù)類型

1.字符串

print("-------------字符串操作-------------");
#coding=utf-8
str = 'Hello World!'
print(str) # 輸出完整字符串
print(str[0]) # 輸出字符串中的第一個(gè)字符
print(str[2:5]) # 輸出字符串中第三個(gè)至第五個(gè)之間的字符串
print(str[2:]) # 輸出從第三個(gè)字符開始的字符串
print(str * 2) # 輸出字符串兩次
print(str + "TEST") # 輸出連接的字符串
print("-------------格式化輸出-------------");
x="歡迎您,%s,當(dāng)前第%d 次訪問! "
y=x%("小明",1)
#y=("歡迎您,%s,當(dāng)前第%d 次訪問! "%("小明",1)),以上兩行可以合并為這一行。
print(y)
print("-------------三引號(hào)-------------");
hi = '''hi
there'''
print(hi) # str()
D:\工作空間\Python\venv\Scripts\python.exe D:/工作空間/Python/main.py
-------------字符串操作-------------
Hello World!
H
llo
llo World!
Hello World!Hello World!
Hello World!TEST
-------------格式化輸出-------------
歡迎您,小明,當(dāng)前第1 次訪問! 
-------------三引號(hào)-------------
hi
there

進(jìn)程已結(jié)束,退出代碼0

到此這篇關(guān)于Python基礎(chǔ)知識(shí)+結(jié)構(gòu)+數(shù)據(jù)類型的文章就介紹到這了,更多相關(guān)Python結(jié)構(gòu)數(shù)據(jù)類型內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • 介紹Python中的fabs()方法的使用

    介紹Python中的fabs()方法的使用

    這篇文章主要介紹了介紹Python中的fabs()方法的使用,是Python入門當(dāng)中的基礎(chǔ)知識(shí),需要的朋友可以參考下
    2015-05-05
  • Python實(shí)現(xiàn)繪制3D條形圖的示例詳解

    Python實(shí)現(xiàn)繪制3D條形圖的示例詳解

    這篇文章主要為大家學(xué)習(xí)介紹了如何利用Python實(shí)現(xiàn)繪制3D條形圖,文中的示例代碼講解詳細(xì),具有一定的學(xué)習(xí)價(jià)值,感興趣的小伙伴可以了解一下
    2023-07-07
  • Python數(shù)據(jù)分析庫pandas基本操作方法

    Python數(shù)據(jù)分析庫pandas基本操作方法

    下面小編就為大家分享一篇Python數(shù)據(jù)分析庫pandas基本操作方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧
    2018-04-04
  • 淺析Python中的序列化存儲(chǔ)的方法

    淺析Python中的序列化存儲(chǔ)的方法

    這篇文章主要介紹了Python中的序列化存儲(chǔ)的方法,序列化存儲(chǔ)主要針對(duì)的是內(nèi)存和硬盤之間的寫入操作,需要的朋友可以參考下
    2015-04-04
  • Python迭代和迭代器詳解

    Python迭代和迭代器詳解

    本篇文章主要介紹Python的迭代和迭代器,可迭代對(duì)象的相關(guān)概念,有需要的小伙伴可以參考下
    2016-11-11
  • Python中Enum使用的幾點(diǎn)注意事項(xiàng)

    Python中Enum使用的幾點(diǎn)注意事項(xiàng)

    Python中的枚舉是作為一個(gè)類存在的,這是與其他語言的一個(gè)較為鮮明的特征,下面這篇文章主要給大家介紹了關(guān)于Python中Enum使用的幾點(diǎn)注意事項(xiàng),需要的朋友可以參考下
    2022-02-02
  • Django程序的優(yōu)化技巧

    Django程序的優(yōu)化技巧

    如果你的Python程序或Django項(xiàng)目運(yùn)行速度慢,先別急著怪Python或Django。其實(shí)程序運(yùn)行效率是可以通過提升硬件水平、架構(gòu)和數(shù)據(jù)庫優(yōu)化和改進(jìn)算法來大大提升的。今天大江哥將分享一些主要Django性能優(yōu)化手段,完全可以讓你的Django程序跑得飛快。
    2021-04-04
  • Python線程之同步機(jī)制實(shí)際應(yīng)用場(chǎng)景舉例說明

    Python線程之同步機(jī)制實(shí)際應(yīng)用場(chǎng)景舉例說明

    這篇文章主要給大家分享的是Python線程之同步機(jī)制實(shí)際應(yīng)用場(chǎng)景舉例說明,銀行轉(zhuǎn)賬小栗子供大家參考學(xué)習(xí),希望對(duì)你有一定的幫助
    2022-02-02
  • Python matplotlib以日期為x軸作圖代碼實(shí)例

    Python matplotlib以日期為x軸作圖代碼實(shí)例

    這篇文章主要介紹了Python matplotlib以日期為x軸作圖代碼實(shí)例,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2019-11-11
  • Python類方法__init__和__del__構(gòu)造、析構(gòu)過程分析

    Python類方法__init__和__del__構(gòu)造、析構(gòu)過程分析

    這篇文章主要介紹了Python類方法__init__和__del__構(gòu)造、析構(gòu)過程分析,本文分析了什么時(shí)候構(gòu)造、什么時(shí)候析構(gòu)、成員變量如何處理、Python中的共享成員函數(shù)如何訪問等問題,需要的朋友可以參考下
    2015-03-03

最新評(píng)論

新郑市| 宜昌市| 金寨县| 蛟河市| 历史| 马关县| 抚宁县| 建水县| 民权县| 北安市| 铜川市| 蓝田县| 汤原县| 城固县| 浏阳市| 张家川| 从化市| 布尔津县| 灌南县| 武定县| 禹城市| 华坪县| 成安县| 漳平市| 封开县| 错那县| 青铜峡市| 全州县| 荃湾区| 迁西县| 临西县| 瑞昌市| 永城市| 云阳县| 汾西县| 定兴县| 自贡市| 嘉鱼县| 邹平县| 七台河市| 柯坪县|