Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 2800ba8

Browse files
Create 03_Walrus_Operator.MD
1 parent 5152327 commit 2800ba8

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

‎Lecture_17/03_Walrus_Operator.MD

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# **Walrus Operator**
2+
it is new to pyhton 3.8. It is also known assignment expression aka walrus operator. It assign values to variables as part of a larger expressions.
3+
4+
Walrus Operator looks like: :=
5+
6+
**Example 1:**
7+
8+
```py
9+
happy = True
10+
print(happy)
11+
```
12+
Applying walrus operator to Example 1:
13+
14+
```py
15+
print(happy := True)
16+
```
17+
18+
**Example 2:**
19+
20+
```py
21+
food = list()
22+
while True:
23+
food = input("What food you like: ")
24+
if food == 'quit':
25+
break
26+
food.append(food)
27+
```
28+
29+
Applying walrus operator at Example 2:
30+
31+
```py
32+
food = list
33+
while food := input("What food do you like?: ") != 'quit':
34+
food.append(food)
35+
```

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /