ノートテキスト
ページ1:
Python
.
หากชื่อแน่ะไม่สามารถวันจะได้
function (Indentation) 112:189992
Variable microanaly
.
.
.
วชนกับยลข
ไม่มั่งว่าง
ไม่มี (-) ในชื่อ ปร
Data Type
.
• Numeric int (Integer), float (floating point Number)
:str (String)
Text
.
Boolean : bgol
Sequence
Mapping
list
: dict
into
float csion)
X-10
X-10.9
string
x= "Hello"
bool (True, false)
X-Trus
y=999
y=97.99
emyjemy then"
y-False
2-20
Z=3.141592
2. "String"
y.[10, 50, 100, 800, 999]
list (ทุกข้อมูลเป็นลำดับ ที่ index รูปตำแหน่ง
x = ["cat", "dog", "bird", "fish"]
≈ = L-100, -2, 0.8, 76 ]
x= {"name" 'cat",'
Dictionaries a key (index) & value (keep)
age
": 23
y=
•{"class": "python"}
10
Z= "tel": "123-456-7893
Type Costing
.
into
แปล ใ น in!
Ex.
age1
= str(20)
0
float C )
A
float
ager
• str()
str
* hr(s)
print (type Lage, type lager))
20,80
Operators minimum (Arithmetic Operators)
+ : นาด
- : คน
* : คุณ
.
** : ก า
% : myim Me
.
1 : 971
.
ทา ไม่เอาน
ページ2:
.
=
.
.
.
.
fe
..
* =
: h u
: นา ก้น
: คนท น
: คุณเก้น
Assignment Operators)
** = ·
.
•
.
.
ท่าน
le : mrhiu
ทา ไม่เอาคนเท่ากัน
2% - : mะเทศ เช่น
ดำเนิน เปรียบเทียบ Comparison Operators)
== : mm น
.
< : Soyo
•>- : มากกว่า
น
.
!= : ไม่เท่
บ
.
> : มากกว่า
• <- : ห้องกวาง น
mainimignomimanami (Logical Operators)
mÀ : และ
. or : mo
.
no : นิเตอ
Conditions if - else (เมงจะทำอะไร
พานเซ็งจะทำอะไร)
List
• X = = y = x nu y
•
kimnuy
X! = y = X
• X > y : x wannar y
->
Index -
.
.
x <y : X Mounny
• X > = y: Xuy
:
• x <= y = xy
· animal-list = ["cat", "dog", "duck", "rabbit", "sheep"]
-5
-4
-3
-2
→cat dog duck rabbit sheep
0 1 2
Ex. animal list t17
animal_list [0:31
animal_list [3]
3
4
dog
["cat", "dog", " duck"]
["cat", "dog", " duck"]
animal_list [2]
C" duck", rabbit", "Sheep"]
animal_list [-3-1] (" duck", "rabbit"]
Access to list
เท) เนินตาคมจาก s lis
Ex. print type canimal-list
<class 'list'>
Ex. print den animal - list))
5
animal-list =["cat", "dog", "duck","
"rabbit", "sheep"]
ページ3:
append() to ekend.t) เป็นความข้อมูลให้กับลูกควาย " Ex. add animal pig" animal-list append cadd animal) - "I"cat", "dog", "duck", "rabbit", "sheep", "pig"] Ex. add animal = ["pig", "tox", "deer"] animal list. extend add_animal) - " ["cat", "dog", " duck", "rabit", "sheep", "pig", "tox", "deer"] remove () tumsalivo popt) เพจบอมูลว่ากันลูกตาย Ex. remove_animal = "de " animal-list.remove [remove_animal) - ["cat", "dack", "rabbit", "sheep" ] Ex. animal-list.pop() - " ["cat", "dog", "duck", "rabbit" ] 3 ) เป็นจัด กับข้อมูล Ex. number_list = [999, 100,80,98, 40, 50, 101 number_list. sort () Loop - → [10,40, 50, 80, 98,100,999 1 EX. number list [40, 50,10,999, 100 80 98] number_list. sort creverse=True) - • [999, 100, 98, 80 50,40,101 While Loop (Loop Tidity, Amanation condition Soc while Condition: Ex.i-0 1=0 ✓ while i4-2: print ci - X mryn while loop Ex. i=0 while i4-2 print cis if i=1 it break ->
ページ4:
For Loop ของจากจะไป loop Autose) "Python", for i in name Ex for i in name: P on print ci -5-4-3-2-1 name= Py th 01 2 3 4 5 hEx for i in name [s] ho print ci Ex. for i in name [-1] mruyn for loop Ex for animal-list = ["cat", "dag", " duck","rabbit", "sheep"] -5 -4 -3 -2 Index cat dog duck rabbit sheep print ci h 0 n i in animal_list: → cat if i == "rabbit": break 0 1 2 3 4 print ci dog duck List · . Lists are ordered, mutable collections that store multiple items. Lists are defined using square brackets [], with items seperated by commas. Ex students "Alice", "Bob", "Charlie") print cotudents) L'Alice', 'Bob', 'Charlie') Indexing and Slicing Lists Python use zone-based indexing to acess elements. Ex. Accessing elements students "Alice"Bob", "Charlie"] first-student students [0] second student students [1] - Alice Bob Slicing a list students = ["Alice", "Bob", "Charlie", "Meraket"] group = student [1:41 print (group) → ['Bob'," Charlie', 'Moraket"]
ページ5:
.
.
.
Modifying Lists
Adding and Removing Lists
Ex. Accewing a student
students, append ("David") ["'Alice', 'Bob", " Charlie", "Moraket, 'David' I
Removing a student
students. remove ("Bob") → ['Alice', 'Charlie', 'Moraket, 'David']
print (students)
List Methods
appendc item)
insert citem, item)
pop Lindex)
sort)
revene ()
เพิ่ม item ที่ข้าง m
: uman item nung index.
- ลบและส่งกันค่าของ item ที่แห่ง index
: เ ง า น
: กลับสากันทยMs
Ex. students. inert C, "Eve")
print (students)
→ L'Alice', ' Eve', ' Charlie', 'Moraket, 'David']
Ex. lowt_student = students. pop ()
print ("hemoved: ", lost student)
List with Multiple Data Types
->
Removed: David
Python lists can stored different types of data in a
Ex. List containing multiple data types
student into "Alice", 20, 3.8, True]
Accessing elements
3
name student-info [0]
=
age = student-info [1]
gpa-student-info [2]
# String
#Integer
# Float
is-enrolled student-info [3] # Boolean
=
single list.
print of "Name : Inames, Age: Lages, GPA: Igpat, Gnrolled: { is _ enrolled'}")
student-info. insert (1,0983211020")
print (student_info)
-
Name: Alice, Age: 20, GPA: 3.8, Enrolled: True
L'Alice' '0983211020", 20, 3.8, True]
ページ6:
.
.
Using Range () to create lists
range() function generates a sequence of numbers starting from a
given value cdefault o), incrementing by a step dufault 1), and stopping before
a specified limit.
Ex. student_ids [f"${100 + 1}" for i in range (9)]
=
print cstudent_ids)
Nested List
-> L's 100', '$109", "'$902', '$903', '$104']
A nested list is simply a list that contains other lists as its elements.
Ex. A nested list
Tuples
students=[
]
["Alice", 20], ["Bob", 21], ["Charlie", 22]
->
print students (23 (71) 22
Tuples are ordered, immutable collections.
• Once created, their values cannot be changed.
.
Ex. exam scores 085,90,78)
print cexam scores)
Accessing and Slicing Tuples
Tuples support indexing and slicing.
Ex. first score exam_scores [0]
top_score = exam_scores [2]
print (first_scores)
print (top-scores)
Packing and Unpacking Tuples
2
0851076)
85
→185,90)
Ex. student = ("Alice", 20, "Computer Science")
#Unpaching tuple
name, age, major student
print Cf "Name: Iname, Age: Lagel, Major: {major}")
Name: Alice, Age: 20, Major: Computer Science
ページ7:
Sets
.
•
.
Sets are unordered allections that store unique items.
Sets are defined wing curly braces {}.
Ex. registered - students = { "Alice", "Bob","
>
print cregistered _ students)
Adding and Removing Elements
.
Use add and remove ()
Ex. registered-students. add ("David")
registered-students. remove ("Bas")
print cregistered _ students)
Set Operatios
"Charlie"}
{'Alice', 'Charlie', ' Bob' }
{'Alice', 'Charlie', ' David"}
Sets support union, intersection, and difference.
Ex. class A "Alice", "Bob", "Charlie"}
class-A "Charlie","David", "Eve" I
#union call students)
all_student class A dow-B
#intersection students in both classes)
Common students claw_A1 claw-B
# difference students only in class A)
exclusive-Aclan-A-clau-B
print ("All: ", all students)
print common:", common students)
print only in A: ", exclusive _A)
-
• All: L'Alice', 'Charlie', 'Bob', 'David', 'Eve's
Common {'Charlie'}
Only in A: L'Alice', 'Bob'
List Tuple Set
Feature
Ordered
Mutabla
Duplicates Allowed
Yes
yes
No
yes No
Yes
Yes
YW
No
No
No
Yes
Fast Membership Check cin
Performance
Moderate fastest Fast for
Cread-only checking
membership
ページ8:
Dictionaries
.
.
Dictionaries store key-value pairs for structured data.
Defined using Ikey: value & pairs.
Ex. grades 3 "Alice": 90, "Bob" : 85, "Charlie" : "8"}
print (grades) { 'Alice': 90, "Bob" : 85, 'Charlie'": 88}
->
Accessing and Modifying Values
Ex. alice-grade grades ("Alice"]
grader "Bob"]=92
print C'Alice's Grade: ", alice - grade)
print ("Updated Grades : ", grades)
-
Alice's grade: 90
• Updated grades: { "Alice": 90) Bob' : 92, 'Charlie': H}
Dictionary Methods
keys () :
values():
-
itema () -
Ex. print (grades. keys (1)
print cgrade values())
-
print cgrade). get ("bve", "Not Found"))
• dict_keys (["Alice", "Bob", "Charlie"])
dict values ([99,92,88]]
->
->
Not found
.
Nested Dictionary
Ex. students=
3
"Alice": "age": 10, "major": "cs"},
"Bob" : "age": 2, "major":"Math" |
print students ["Alice"][ "major"])
.
Iterate Through Dictionaries
Ex. # Dictionary storing student grades.
grades = 1°
->
CS
"Alice": 90, "Bob" : 85, "Charlie" : 88
ページ9:
for student in grades. keys():
print cstudents
Alice
Bob
Charlie
for student, score in grades. items():
print of "{ students: Is one !")
Alice: 90
-
Bob: 85
Charlie88
☆
おすすめノート
このノートに関連する質問
Undergraduate
วิศวกรรมศาสตร์
พี่ๆครับคือผมอยากปรึกษาปัญหาของผมคือ ตอนนี้ผมอยู่ปี 1 พึ่งเริ่มเรียนไป 2สัปดาห์ผมไม่รู้เรียนเรยผมเรียนวิศวะ เพราะตอนมัธยมผมไม่ตั้งใจเรียนเรยเอาง่ายๆผมแถบไม่ได้ความรู้อะไรจากม.ปลายเรยครับ ผมควรทำไงดีครับ หาหนังสืออ่านหรือว่าทำไงดีครับเรียนพิเศษคงไม่มีเวลาหรือหาเรียนในยูทูปแนะนำหน่อยครับนั้นผมว่าผมไปไม่รอดแน่ช่วยผมหน่อยครับ🙏🙏🙏
Undergraduate
วิศวกรรมศาสตร์
ใครพอจะรู้โค้ดของ Aduino voice recognition module v3.1 คำสั่งทำให้มันพูดตามเราได้บ้างคะ
News


コメント
コメントはまだありません。