Written by students who passed Immediately available after payment Read online or as PDF Wrong document? Swap it for free 4.6 TrustPilot
logo-home
Class notes

8 IMPORTANT TOPICS OF PYTHON PROGRAMMING

Rating
-
Sold
-
Pages
4
Uploaded on
22-05-2023
Written in
2022/2023

Its is very important for python programmers and mainly for beginners Described in simple and easy way to understand

Institution
Course

Content preview

8 Important Concepts and Language Features in Python

In this short video, we will discuss eight important concepts and language features in Python that
are essential to know.

References

When you assign a variable to another variable, you are creating a reference in the computer's
memory and storing it in the variable. Changing the value of a variable is actually making it refer
to a completely different value in memory. Immutable values like integers do not change, but
mutable data types like lists can be altered. To change a value inside a list, you can simply assign
a new value to a specific index.

Functions

To define a function, you need to use the def keyword. You can then use the function by
invoking it with arguments. You can also define anonymous functions or lambda expressions
using the lambda keyword. However, you cannot use them directly without giving them a
name.

Iterators and Generators

Iterators are objects used to iterate over iterable objects like lists, tuples, dictionaries, and sets.
The __next__() method is used to return the next value in the iterable. Generators are
functions that return iterators and are used to create a new collection of data.

The Yield Keyword

The yield keyword is used in Python to create generator functions. It is used in the context of a
function that takes input or data, processes it and returns a new collection of data. When
the yield keyword is encountered, it returns a value and pauses the function's execution. The
next time the function is called, it resumes from where it left off.

The yield keyword comes in handy in situations where we don't want a temporary collection
and we don't want to iterate multiple times before returning the value. To use
the yield keyword, we will delete the list and replace the res.append with yield. When
we get to the line with yield, we take that value and send it out of the function as the next
element in the sequence. If we iterate over each value, each value is handed over immediately
while suspending the function for a second. So, the process of iterating stops briefly till you ask
for the next item.

For a practical example, let's create a function called cube that takes an input of num, multiplies
each number from 1 to 5 by 3, and returns the list of numbers. We'll invoke our cube function
and return the list.

Written for

Institution
Course

Document information

Uploaded on
May 22, 2023
Number of pages
4
Written in
2022/2023
Type
Class notes
Professor(s)
Me
Contains
All classes

Subjects

$8.49
Get access to the full document:

Wrong document? Swap it for free Within 14 days of purchase and before downloading, you can choose a different document. You can simply spend the amount again.
Written by students who passed
Immediately available after payment
Read online or as PDF

Get to know the seller
Seller avatar
rahulreddyrb6

Get to know the seller

Seller avatar
rahulreddyrb6 pvp sit
Follow You need to be logged in order to follow users or courses
Sold
-
Member since
2 year
Number of followers
0
Documents
2
Last sold
-

0.0

0 reviews

5
0
4
0
3
0
2
0
1
0

Recently viewed by you

Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Working on your references?

Create accurate citations in APA, MLA and Harvard with our free citation generator.

Working on your references?

Frequently asked questions