Learniverse

Mastering Python: A Beginner's Guide

00:00

Welcome to the Complete Python Master Recourse.

00:04

In this course, you're going to learn everything about Python from basics to more advanced

00:08

concepts.

00:09

So by the end of the course, you'll be able to confidently use Python for AI, machine learning,

00:14

web development and automation.

00:16

If you have been looking for a comprehensive, easy to follow, well-organized and practical

00:20

course that takes you from zero to hero, this is the right Python course for you.

00:25

You don't need any prior knowledge of Python to get started.

00:27

I will explain everything step-by-step in simple terms so you can build a solid foundation.

00:33

I'm Marsh Hamadani, a software engineer with over 20 years of experience, and I've taught

00:37

millions how to code and become professional software engineers through my YouTube channel

00:42

and online school called bitmash.com.

00:45

If you're new here, make sure to subscribe as I upload new videos all the time.

00:49

Now, let's jump in here, you'll start it.

00:58

In this course, you're going to learn everything you need to get started with Python.

01:02

Just be aware that I've designed this course for beginners.

01:05

So if you have some programming experience, check out my other Python course for developers.

01:10

You can see the link on the top-right corner of this video.

01:13

So, Python is the world fastest growing at most popular programming language,

01:19

not just amongst software developers, but also amongst mathematicians, data analysts, scientists,

01:27

accountants, network engineers, and even kids.

01:30

In fact, it's the ideal programming language to learn first.

01:34

But what makes Python so special?

01:36

Here are six reasons.

01:38

With Python, you can solve complex problems in less time with fewer lines of code than many other languages.

01:45

That's why huge companies like Google, Spotify, Dropbox, and Facebook

01:51

have embraced this beautiful and powerful language.

01:55

Here is an example.

01:56

Let's say we want to extract the first three characters of the text hello worth.

02:02

This is the code we would have to write in C-sharp.

02:05

This is how we would do this in JavaScript, and here's how we would do it in Python.

02:10

See how clean and simple the language is?

02:13

And that's just the beginning.

02:15

Python is a multipurpose language, and you can use it for a wide range of jobs,

02:19

such as data analysis, AI and machine learning,

02:23

writing automation scripts, building web, mobile, and desktop applications,

02:28

as well as software testing or even hacking.

02:31

So if you want a high paying, long-lasting career in any of these areas,

02:36

especially AI and machine learning, Python is the language to put those opportunities at your fingertips.

02:44

In fact, according to Indeed.com, the average salary of a Python developer in the US

02:50

was over $15,000 in March 2018.

02:55

And here are four more reasons that make Python the most desirable language.

03:00

Python is a high-level language, so you don't have to worry about complex tasks,

03:05

such as memory management as you do in C++.

03:08

It's cross-platform, which means you can build and run Python apps on Windows,

03:13

Mac, and Linux.

03:15

It has a huge community, so whenever you get stuck, there is someone out there to help.

03:20

And it has a large ecosystem of libraries, frameworks, and tools.

03:25

Whatever you want to do, it is likely that someone else has done it before,

03:29

because Python has been around for over 20 years.

03:33

There are two versions of Python out there, Python 2, which is the legacy version of Python,

03:38

and it's going to be supported until year 2020.

03:42

And Python 3, which is Python for the future.

03:45

In this course, you're going to learn Python 3.

03:48

Hi, my name is Mosh Hamadani, and I'm going to be your instructor in this course.

03:52

I'm a software engineer with 18 years of experience,

03:55

and I have taught way over a million people how to code,

03:59

or how to become top professional software engineers.

04:03

To learn more about me and my courses, head over to code with Mosh.com.

04:07

All right, now let's get started.

04:13

Alright, the first thing I want you to do is open your browser and head over to Python.org.

04:18

On this page, on their download, you can download the latest version of Python.

04:22

At the time of this video, the latest version is Python 3.13.

04:26

Chances are in the future, when you're watching this video,

04:29

there is a newer version of Python available.

04:31

Don't worry, what I'm going to show you in this tutorial,

04:33

will apply to future versions of Python as well.

04:36

So go ahead and download the latest version.

04:39

Now, if you're on Windows, before you click install,

04:42

make sure to check this little box here that says,

04:45

at Python to path.

04:46

This step is very important, and it will save you a lot of headaches later.

04:50

So check this box and follow the installation.

04:53

Now, to verify that Python is successfully installed,

04:57

click this magnifier, and here in this search bar, type terminal.

05:02

Now, here in the terminal, window, type Python,

05:06

dash dash version.

05:08

This verifies that we have successfully installed Python 3.13.

05:12

Now, if you're on Mac, press command and space to bring up the spotlight search.

05:18

Here type terminal.

05:20

Now, to verify that we have installed Python correctly,

05:23

on Mac, we should type Python 3,

05:26

space, dash, dash version.

05:29

So, as you can see, of successfully installed,

05:32

Python 3.13 on this machine.

05:36

So, this environment you see here is what we call Python interpreter,

05:45

which is basically a program that executes Python code.

05:49

We can type our Python code in a file and give it to this interpreter,

05:52

or we can type our code directly here in this interactive shell.

05:57

So here we can write an expression like 2 plus 2,

06:00

in programming, an expression is a piece of code that produces a value.

06:05

So here, when we add 2 plus 2, we get a value,

06:09

that is why we refer to this piece of code as an expression.

06:12

So enter, we get 4.

06:14

Let's try a different kind of expression.

06:17

Let's see if 2 is greater than 1.

06:20

We get true, which is an example of a Boolean value,

06:24

you're going to learn about these Boolean values in the next section.

06:27

Now, what if we type 2 is greater than 5?

06:31

Enter, we get false.

06:34

So in programming, we have true and false,

06:37

which are similar to yes and no in English.

06:40

Now, what if we type 2 is greater than,

06:43

what we don't add a second value here, just press enter,

06:47

we get a syntax error.

06:49

In programming, syntax means grammar.

06:52

So just like we have the concept of grammar in the languages that we speak,

06:56

we have the exact same concept in programming.

06:59

If we write a sentence, that is not grammatically correct,

07:02

chances are some people may not understand that sentence.

07:05

So in this example, we have this expression, which is incomplete.

07:09

It doesn't have the right grammar or syntax.

07:12

That is why Python interpreter is complaining by returning an error.

07:17

So this interactive shell is a great way to quickly experiment with a bit of Python code.

07:22

But that's not how we build real-world applications.

07:25

To do that, we need a code editor.

07:27

And that's what I'm going to show you in the next lecture.

07:32

When it comes to typing Python code, you have two options.

07:39

You can use a code editor or an IDE, which is short for integrated development environment.

07:46

An IDE is basically a code editor with some fancy features like auto-completion,

07:52

which means as you type code, this feature helps you complete your code.

07:56

So you don't have to type every character by hand.

07:59

It's a productivity boosting feature.

08:01

It also gives you additional features like debugging, which means finding and fixing bugs in your programs, testing and so on.

08:09

For both code editors and IDE's, there's so many options out there.

08:13

The most popular code editors are VS Code, Adam, and Subline.

08:18

You can use the code editor that you prefer.

08:21

In terms of the IDE's, again, there's so many options out there.

08:24

The most popular one is Python.

08:27

In this course, I'm going to use VS Code or Visual Studio Code, because that's my favorite code editor.

08:33

Later, in the course, I will show you how to install a plugin or an extension that will convert VS Code to a powerful IDE.

08:40

So, before going any further, head over to code.visualstudio.com and download the latest version of VS Code.

08:49

Now, with VS Code open, on the top, from the file menu, go to Open and somewhere on your disk create a new folder.

09:04

Let's call this folder, hello world.

09:08

And then open it, beautiful.

09:12

Now, click this icon on the top.

09:14

This opens up the Explorer panel.

09:17

In this panel, you can see all the files and folders in your project.

09:21

So, let's add a new file and call that app.py.

09:26

So, all our Python files should have thepy extension.

09:31

Presenter.

09:32

Now, let's close this and type a bit of Python code.

09:37

In this lecture, we're going to use one of the built-in functions in Python called Print.

09:42

So, in Python, we have a lot of built-in functions for performing various kinds of tasks.

09:47

For example, as a metaphor, think of the remote control of your TV.

09:51

On this remote control, you have a bunch of functions.

09:54

Like, turn on, turn off, change the channel, change the volume and so on.

09:58

These are the built-in functions and your TV.

10:01

We have the same concept in Python and many other programming languages.

10:05

So, one of these built-in functions that comes with Python is Print.

10:11

And we can use this to print something on the screen.

10:14

Now, whenever you want to use a function, you should open and close parenthesis.

10:19

In programming, we say, we're calling the print function.

10:23

Calling a function means executing it.

10:26

Now, let's display the Hello World Message on the screen.

10:30

Whenever you want to work with text, you should put your text in between quotes.

10:35

Either double quotes or single quotes.

10:39

Now, I'm going to go with double quotes and add Hello World.

10:45

And then put a happy Persian cat here.

10:48

Beautiful.

10:49

Save the changes with command and S on Mac or control and S on Windows.

10:55

Now, to execute this code, we need to go back to command prompt on Windows or terminal on Mac.

11:01

But the good news is that we don't have to switch programs.

11:04

Here in VS Code, we have an integrated terminal.

11:07

So press, control and back tick.

11:10

That is the key before number one on your keyboard.

11:14

That is just below the Scape button.

11:17

So, this is our integrated terminal.

11:20

Now, you're from Windows type Python.

11:22

If you're on Mac or Linux type Python 3,

11:25

and next to that, add the name of our file.

11:28

That is app of Python.

11:31

And here's our Hello World Message in the terminal.

11:34

Beautiful.

11:35

Now, let's take this to the next level.

11:37

I'm making it a little bit more interesting.

11:39

Let's close this terminal window by pressing control and back tick.

11:44

And add a second line of code.

11:47

So one more time, print.

11:49

This time, let's add quotes with a star in between them.

11:54

Now, let's say we want to repeat this star 10 times.

11:57

So here, we can multiply this by 10.

12:01

Save the changes.

12:03

Open up the terminal and run our program.

12:07

And you can see this star is repeated 10 times.

12:11

So, as you see, the instructions on our program are executed

12:15

from top to bottom in order.

12:17

In the next lecture, I'm going to show you how to convert this VSCode

12:21

to a powerful IDE for building Python applications.

12:29

In this lecture, I'm going to show you how to convert VSCode

12:32

to a powerful IDE by using an extension called Python.

12:36

With this extension or plugin, we get a number of features,

12:40

such as linting, which basically means analyzing our code

12:44

for potential errors.

12:46

We also get debugging, which involves finding and fixing errors.

12:50

We'll look at this later in the course.

12:52

We also get auto-completion, which basically helps us write code faster,

12:57

so we don't have to type every character.

13:00

We get code formatting, which is all about making our code clean and readable,

13:04

just like how we format our articles, newspapers, books to make them clean and readable.

13:10

We get unit testing, which involves writing a bunch of tests for our code.

13:15

We can run these tests in an automated fashion to make sure our code is behaving correctly.

13:21

And finally, we get code snippets, which are reusable code blocks

13:26

and we can quickly generate, so we don't have to type them all by hand.

13:30

But don't worry about memorizing any of these.

13:32

As we go through the course, you're going to learn about these features.

13:36

So back to VSCode, on the left side, click this icon.

13:40

This opens the extensions panel, where we can install additional extensions

13:44

to enhance VSCode.

13:45

Up here in the search bar, search for Python.

13:49

Alright, look, we have an official extension for Python from Microsoft.

13:54

So go ahead and install this.

13:57

Now you might see a box here saying reload.

14:00

If you see that, make sure to click it to reload VSCode.

14:03

Now with this extension installed, we have a ton of new functionality VSCode for writing Python code.

14:08

The first one I'm going to show you in this lesson is the ability to run our code.

14:12

So back to app.py, look with this extension installed.

14:17

Now we have this play icon on the top for running our code.

14:20

So if we click it, we can see the output of our program in the terminal window.

14:31

In this lecture, I'm going to show you a linting and action.

14:34

So let's start by writing some invalid code like this.

14:38

Print, space with no parentheses, and then hello world.

14:43

Earlier I told you that print is a built in function,

14:46

and whenever you want to use or call a function, you should always use parentheses.

14:51

Now to be more precise, this is actually valid Python 2 code,

14:55

but because we're using Python 3 here, this is invalid code from Python 3's point of view.

15:01

So now when I saved the changes, you can see this read on the line here.

15:06

Let's hover our mouse over this underlying.

15:09

You can see this tool tip.

15:11

It's coming from pilot, and here's the error message, missing parentheses in call to print.

15:17

Did you mean print with parentheses?

15:19

So this is the benefit of linting.

15:21

As you're writing code, you can see potential problems in your code.

15:25

You don't have to wait to run your program to see these errors.

15:29

So now, if we put parentheses here and save the changes, you can see that read on the line is gone.

15:37

Let's look at another error.

15:40

Let's type 2 plus and then save the changes.

15:44

Earlier, we ran this code and Python interpreters interactive shell.

15:49

There, we got a syntax or grammar error.

15:53

So if you hover your mouse here one more time, you can see,

15:56

Pylints is telling us that this is invalid syntax or invalid grammar.

16:01

It's like an incomplete sentence.

16:04

So this is linting an action.

16:06

Now let me show you a couple useful shortcuts here.

16:09

On the top, look at the view menu.

16:12

Here we have this problem's menu.

16:15

Look at the shortcut.

16:16

On Mac, it's Shift, Command, and M.

16:19

On Windows, it's probably Shift, Control, M.

16:22

So as you're working with VS code, try to memorize these shortcuts

16:26

because they really help you write code faster.

16:29

Now let's take a look at this problem's panel.

16:33

So this problem's panel lists all the issues in your code in one place.

16:38

So if you have an application with multiple files, this is really useful

16:42

because some of those files may not currently be open.

16:45

So this linter, Pylint, will analyze all your files.

16:49

And if it finds any issues, it will list them here in the problem's panel.

16:53

Now you can also put this on the right side of the screen.

16:56

So let's put it here.

16:58

So as you write code, these problems will appear here.

17:02

Now let's fix this issue.

17:04

Now I'm going to add three here, save the changes, and you can see the problem disappear.

17:10

And one last thing before we finish this lecture.

17:12

Once again, on the top, let's go to the view menu.

17:16

The first item is Command Palat.

17:19

This is a very important feature in VS code.

17:21

Once again, look at the shortcut that is Shift, Command, and P on Mac,

17:26

or Shift, Control, P on Windows.

17:29

With this Command Palat, you can execute various commands in VS code.

17:33

If you type Lint here, you can see all commands related to Linting.

17:38

As you can see, all these commands are prefix with Python,

17:42

because these commands come with a Python extension that we installed earlier.

17:47

So these are additional features available to us in VS code.

17:51

The first command here is Select Linter.

17:54

In this list, you can see various Linter's available for Pylint.

17:59

So as you're reading tutorials or talking to other people,

18:02

you will hear about Linters such as Flake 8, My Pie, Pep 8, and so on.

18:07

Different developers prefer different Linters.

18:10

I personally prefer Pylint.

18:12

That is the most popular one, and that is the default Linter set in the Python extension of VS code.

18:19

If you're adventurous, you can try using other Linters on your own.

18:23

The difference between these Linters is in how they find and report errors.

18:28

Some error messages are more meaningful or more friendly.

18:32

The others are more ambiguous.

18:34

So that's all about Linting.

18:36

In the next lecture, we'll talk about formatting code.

18:45

In Python community, we have a bunch of documents called Python enhancement proposals or peps.

18:52

Here on Google, if you search for Python peps,

18:57

you can see the list of all these peps under python.org slash dev slash peps.

19:03

Let's have a quick look here.

19:07

So here are the peps.

19:08

We can see each pep has a number and a title.

19:12

The one that is very popular amongst Python developers is Pep 8,

19:16

which is a style guide for Python code.

19:19

A style guide is basically a document that defines a bunch of rules for formatting and styling our code.

19:26

If you follow these conventions, the code that you write will end up being consistent with other people's code.

19:32

Now, if you have time, you can go ahead and read this pep 8 documentation.

19:37

But if not, don't worry, because throughout the scores, I'm going to explain the key things in pep 8.

19:42

In this lecture, I'm going to show you a tool that helps you automatically format your code according to pep 8.

19:49

So back in VS code, let's write some Python code.

19:53

X equals one. Here I'm declaring a variable and setting it to one.

19:58

If you're not familiar with variables, don't worry. The next section you're going to learn about them.

20:03

So according to pep 8, this code is considered ugly.

20:07

Because by convention, we should add a space around this equal sign or the assignment operator.

20:14

Now, since you're starting out with Python, you probably don't know these rules.

20:18

So let me show you a tool that helps you automatically format your code.

20:21

Let's revert this back to its original state.

20:24

Now we need to go back to the command palette.

20:27

Remember, so it's right here under view and the shortcut is Shift, command, and P.

20:33

Here if you search for format, you can see this command format document.

20:39

The first time you execute this command, you're going to see this message here.

20:45

For matter, auto pep 8 is not installed.

20:48

So there are a bunch of tools for formatting Python code.

20:51

The most popular one is auto pep 8.

20:54

And this is the tool that this Python extension will install uses to format our code.

20:59

Now if you don't see this, you can install auto pep 8 using the extensions panel.

21:04

So once again on the left side, click the icon and search for auto pep 8.

21:10

There it is. Let's install it.

21:15

Good.

21:16

So let's go ahead and install this.

21:20

Good.

21:22

Now one more time, let's open up the command palette and execute format document.

21:28

See, this tool automatically formats our code.

21:31

Beautiful. Let's take a look at another example.

21:34

I'm going to declare another variable, y and set it to two, and it's variable with a long name.

21:40

Like unit on the line price, I'm set this to three.

21:43

Now some developers have this habit of formatting their variable declarations like this.

21:50

So they put all these equal signs in the same column.

21:55

According to pep 8, this is considered ugly.

21:58

So once again, let's format our code.

22:02

That is better. Beautiful.

22:04

Now let me show you a trick.

22:06

Opening of this command palette and searching for format document every time is a little bit time consuming.

22:12

So I want to show you how to have your file automatically format it as soon as you save the changes.

22:18

On the top, let's go to the code menu, preferences, and settings.

22:25

Here in the search box, search for format on save.

22:31

So we have this option editor format on save.

22:35

Take this.

22:36

Now back to app.py.

22:38

I'm going to change the formatting of these lines.

22:41

Make them really ugly.

22:43

Now as soon as I save the changes, you can see, my code is reformatted.

22:49

Beautiful.

22:56

Alright, that lets talk about a few different ways to run Python code.

22:59

As I told you before, one way to run Python code is by opening the terminal window.

23:04

If you're on Windows type Python, if you're on Mac type Python 3, followed by the name of the file.

23:10

This approach is useful in situations where you don't have access to a code editor.

23:15

Okay. Now with the Python extension in VS code, there is a simpler way to run Python code.

23:20

We get this play button on the top.

23:22

When we click it, we see the output in the terminal.

23:25

But clicking this button every time we change our code is a little bit tedious.

23:29

So let me show you how to associate a shortcut to this button.

23:33

First, we close this.

23:35

Next, we bring up the command palette.

23:37

The shortcut on Mac is shift command and p.

23:40

On Windows is shift control p.

23:43

Here we search for open keyboard shortcuts.

23:47

Look, we have this command up here.

23:49

Now on this window, we can see all the commands in VS code

23:53

and the shortcuts associated with them.

23:56

Here in the search bar, search for run Python file.

24:01

Okay. So this is the command that is associated with the play button.

24:05

As you can see, we don't currently have any key bindings or shortcuts here.

24:10

So double click in this column.

24:12

Now here you can press any key combination for creating a shortcut.

24:16

I'm going to press Ctrl and R.

24:19

Okay. Now we press Enter.

24:22

With this in place, we can go back to app.py and press Ctrl R.

24:27

And here we see the output beautiful.

24:33

Let me talk about Python.

24:34

We mean two separate things that are closely related.

24:37

Python language and a particular implementation.

24:40

Python as language is just a specification that defines a sort of rules and grammar for writing Python code.

24:48

A Python implementation is basically a program that understands those rules and can execute Python code.

24:55

Earlier in the course, with downloaded Python from Python.org,

24:59

this is the default implementation of Python called C Python.

25:03

It's a program written in C. That's why it's called C Python.

25:07

So here in terminal, when we run Python, we get this C Python.

25:12

This is the default implementation of Python.

25:15

There are a few other implementations out there, such as Python, written in Java,

25:20

Iron Python, written in C sharp, and Python written in a subset of Python itself.

25:26

As new features are added to the Python language,

25:29

they are first supported by C Python because it's the default implementation.

25:34

And then they will gradually come to the other implementations.

25:38

In theory, if it gives some Python code to any of these implementations,

25:42

we should get the same result.

25:44

But in practice, that's not always the case.

25:47

Certain features may be available in one implementation, but not another,

25:51

or they may just behave a little bit differently in a particular implementation.

25:56

Now you might ask, what is the point of this?

25:59

Why do we have several implementations of Python?

26:02

Wouldn't C Python be enough?

26:04

Well, it's for the same reason that we have multiple operating systems,

26:08

or multiple browsers, or multiple programming languages.

26:11

After all these years, in programmers haven't agreed on a single programming language.

26:16

And that's the same story with Python implementations.

26:19

However, there is one technical reason behind these implementations that you should be aware of.

26:25

Since JSON is implemented in Java, it allows you to reuse some existing Java code in a Python program.

26:33

So if you're a Java developer, and you want to import some Java code into a Python program,

26:39

you should use Python instead of C Python.

26:42

Similarly, Iron Python is written in C-sharp.

26:45

So if you're a C-sharp developer, and want to bring some C-sharp code into a Python program,

26:50

you will have to use Iron Python.

26:52

Next we will look at how exactly C Python executes Python code.

27:02

The programming languages we use, like C, C-sharp, Java, Python,

27:07

these are all simple text-based languages that we humans understand.

27:12

Computers don't understand them, they only understand machine code.

27:16

So if you have some code written in C, we should convert it to machine code.

27:20

And that's the job of a C compiler.

27:23

So a C compiler is a program that knows how to convert or compile C code into machine code.

27:29

However, this machine code is specific to the type of CPU of a computer.

27:35

So if you compile a C program on a Windows machine, we can't execute it on a Mac.

27:40

Because Windows and Mac have different machine code, just like how people from different countries speak different languages.

27:47

Java came to solve this problem.

27:49

Java compiler doesn't compile Java code into machine code.

27:53

Instead, it compiles it into a portable language called Java byte code,

27:59

which is not specific to a hardware platform like Windows or Mac.

28:04

Now, we still need to convert Java byte code to machine code.

28:07

So Java also comes with a program called Java virtual machine or JVM for doing this.

28:14

When we run a Java program, JVM kicks in, it loads our Java byte code,

28:19

and then at runtime, it will convert each instruction to machine code.

28:24

With this model, we can run Java byte code on any platforms that have a JVM.

28:29

We have JVM implementations for Windows, Mac, and so on.

28:33

So the JVM implementation on Windows knows how to convert Java byte code into machine code that a Windows machine can understand.

28:42

C Sharp and Python have also taken the same route, so they are platform independent.

28:48

When we run a Python program using C Python, first it will compile our Python code into Python byte code.

28:54

Then it will pass that byte code to Python virtual machine,

28:59

which will in turn convert it into machine code and execute it.

29:03

This is how C Python works.

29:05

In the last lecture we talked about various Python implementations.

29:09

I told you that if you want to reuse some Java code in a Python program, you should use Jithon.

29:15

Now, let's see how Jithon makes this possible.

29:18

When you use Jithon to run a Python program,

29:21

instead of compiling your Python code into Python byte code,

29:25

it will compile it to Java byte code.

29:28

Now we can take this Java byte code and run it using Java virtual machine.

29:32

And that's why you can import some Java code into a Python program when using Jithon.

29:37

Because the end result is Java byte code, which will eventually be executed by Java virtual machine.

29:49

So I've got a few questions for you because I want to see if you have been really paying attention to this video or not.

29:54

The better half. So here's the first question.

29:57

For each question, I want you to pause the video,

30:00

think about the answer for a few seconds when you're ready to continue watching.

30:04

So here's the first question. What is an expression?

30:08

An expression is a piece of code that produces a value.

30:13

Here's an example of an expression.

30:15

What do you think is the value of this expression?

30:18

Well, here we have this string.

30:21

We're multiplying this by three.

30:24

So the result will be a string of three asterisk like this.

30:29

Here's another question. What is a syntax error?

30:33

A syntax error is a kind of error that is due to bad syntax or bad grammar in the code.

30:40

And finally, the last question. What does a linter do?

30:45

A linter is a tool that checks our code for potential errors,

30:49

mostly in the category of syntactical errors.

30:52

So if you have grammatical issues in our code,

30:54

the linter will tell us before running our program.

30:57

Okay, that's it for now.

30:59

If you like more quizzes and programming exercises,

31:02

look at the link below this video.

31:04

And if you have enjoyed this video, I hope you have.

31:07

Please support me by giving a thumbs up.

31:10

Please like this video and share it with others.

31:12

In the next section, we're going to look at the fundamentals of Python.

31:17

Hey guys, I just wanted to let you know that this tutorial is actually the first two hours of my complete Python mastery course.

31:24

If you're finding this helpful and want to dive even deeper,

31:27

the full course covers everything from beginner basics to advanced concepts like machine learning,

31:32

web development and automation.

31:34

You also get hands on projects to build your skills step by step.

31:38

I put the link in the description box if you're ready to take your Python knowledge to the next level.

31:43

Now let's continue.

31:48

Let's start this section by discussion of variables,

31:51

which are one of the core concepts in programming.

31:54

We use variables to store data in computer's memory.

31:58

Here are a few examples.

31:59

I'm going to define a variable called students on the line count

32:03

and setting it to 1000.

32:06

When we run this program, Python interpreter will allocate some memory and store this number

32:12

thousand in that memory space.

32:14

Then it will have this variable reference that memory location.

32:20

So this variable is just like a label for that memory location.

32:24

We can use this variable or this label anywhere in our program to get access to that memory location

32:30

and the data stored there.

32:32

So now if we print students count and run our program will get the number thousand.

32:41

So this is the basic of variables.

32:44

Now what kind of data can we store in computer's memory?

32:47

Well, we have several different kinds of data.

32:50

In this section we're going to look at the built in primitive types in Python.

32:55

Primitive types can be numbers, bullions and strings.

33:00

Let me show you.

33:01

So here we have a whole number.

33:03

We refer to this as an integer in programming.

33:06

We can also have numbers with a decimal point.

33:09

Let's take a look.

33:10

So rating we set this to 4.99.

33:14

This is what we call a float or a floating point number.

33:18

And this terminology is not specific to Python.

33:21

In the future, when you learn a new programming language,

33:24

you're going to hear this terms again.

33:26

Now let's take a look at an example of a Boolean.

33:30

Is published with set this to true or false?

33:36

These are examples of Boolean values in programming.

33:40

So Boolean values can either be true or false.

33:43

And these are exactly like yes and no in English.

33:46

Later in the course, you will learn that we'll use this Boolean values

33:50

to make decisions in our programs.

33:53

For example, if the user is an admin user,

33:56

perhaps we want to give them extra permissions.

33:59

So these are the Boolean values.

34:01

Now take into account that Python is a case sensitive language,

34:05

which means lowercase and uppercase characters have different meanings.

34:09

So Boolean values should always start with a capital letter like what you see here.

34:15

If we type false or false, these are not accepted Boolean values in Python.

34:21

Only what you see here is a valid Boolean value.

34:24

The false or true.

34:26

And finally let's take a look at an example of a string.

34:29

So of course, on the line name, we set this to a string like Python programming.

34:36

So a string, as I told you before, is like text.

34:39

Whenever you want to work with text in your programs,

34:42

you need to surround your text with quotes.

34:45

So these are the basics of variables.

34:48

So these are the variables from the last lecture.

34:55

Now I've got a question for you.

34:57

There are four things that have consistently used in this program.

35:01

Can you spot them?

35:02

If you want, you can pause the video.

35:04

Think about this for a few seconds and then continue watching.

35:08

So here are those four things.

35:10

The first thing is that all my variable names are descriptive and meaningful.

35:16

So students count represents the number of students for a course.

35:20

Or course name, cleared explains that this variable holds the name of a course.

35:25

One of the issues that I see a lot amongst beginner programmers is that they use mystical names for their variables.

35:33

Something like this.

35:34

CN, as in short for course name.

35:37

When someone else reads this code, they have no idea what CN stands for.

35:41

Or they use variable names like C1.

35:44

When I look at that code, I wonder, where is C2?

35:47

And what is the difference between C1 and C2?

35:50

So these variable names are very mystical.

35:53

That's a bad practice.

35:55

Make sure your variable names are always descriptive and meaningful because this makes your code more maintainable.

36:01

Now there are times that you can use short variable names like x, y, z.

36:07

If you're dealing with things like coordinates.

36:09

So that's an exception.

36:11

Now the second thing that I have consistently used in this code is that I have used lowercase letters to name my variables.

36:19

So here we don't have course name, all in capital or in title case.

36:26

All letters are lowercase, right?

36:29

Let's delete this.

36:31

The third thing that I've consistently used here is that I have used an underscore to separate multiple words.

36:38

And I've done this to make my variable names more readable.

36:42

Because in Python, we cannot have a space in variable names.

36:46

So we cannot have course name.

36:48

And if you put these two words together, it's a little bit hard to read.

36:52

That's why we use an underscore.

36:54

And the fourth thing that I have used consistently here is that I have put a space around this equal sign.

37:01

Again, that's one of the issues I see a lot amongst beginners.

37:05

They write code like this.

37:08

This is a little bit ugly.

37:10

This is what we call dirty code.

37:13

Dirty, stinky, smelly.

37:15

You should write code that is clean and beautiful.

37:17

So other people can read it like a story, like a newspaper article.

37:22

You should be formatted properly.

37:24

And that's why we have Pepe 8 in Python.

37:27

Now the good thing is if you forget these rules when you save the changes,

37:32

Auto Pepe 8 kicks in, I did automatically reformat your code.

37:36

But that aside, you should always give yourself the habit of writing clean code without relying too much on the tooling.

37:43

So these are all the best practices about naming your variables.

37:47

Next, we're going to look at strings in more detail.

37:55

So here we have this course variable set to Python programming.

37:59

As I told you before, whenever you work with text, you should surround your text with quotes.

38:04

You can either use double quotes or single quotes.

38:07

That's more of a personal preference, but quite often we use double quotes.

38:12

We also have triple quotes and we use them to format a long string.

38:17

For example, if you have, let's say, a variable message,

38:22

that is the message we want to include in the body of an email.

38:27

You can use triple quotes to format it like this.

38:30

Hi, John. This is Marsh from code with marsh.com, blah, blah, blah.

38:38

So that's when we use triple quotes.

38:41

Now we don't need this and this lecture, so delete.

38:44

Let me show you a few useful things you can do with strings.

38:48

First of all, we have this built-in function in Python for getting the length of strings.

38:54

What is a function?

38:56

A function is basically a reusable piece of code that carries out a task.

39:01

As a metaphor, think of the remote control of your TV.

39:05

On this remote control, you have buttons for different functions,

39:08

like turn on, turn off, change the channel and so on.

39:11

These are the built-in functions in your TV.

39:14

In Python and many other programming languages, we have the exact same concept.

39:19

So we have functions that are built into the language on the platform.

39:23

We can reuse these functions to perform various tasks.

39:27

So here we can use the built-in length function to get the length of a string,

39:32

which means the number of characters in that string.

39:35

Now, whenever you want to use a function, you should use parentheses.

39:40

Now we say we're calling this function, which basically means we're using this function.

39:45

Now some functions take additional data, which we refer to as arguments.

39:51

These arguments are inputs for these functions.

39:54

So this length function takes an input on an argument.

39:59

Here we pass our course variable, and this will return the number of characters in this string.

40:06

So let's print that and see what we get.

40:10

Run the program.

40:11

We get 18, because we have 18 characters here.

40:16

Let's look at another example.

40:18

If you want to get access to a specific character in this string, you use the square bracket notation.

40:24

So here we add course, square brackets, to get the first character, you use the index zero.

40:32

So in Python, like many other languages, strings are zero index, which means the index of the first character or the first element is zero.

40:43

So now when we print this, we'll get p, okay?

40:50

Now you can also use a negative index, like minus one.

40:56

What does that mean? Well, if zero represents the first character here, what do you think negative one represents?

41:05

That takes us back to the end of the string.

41:08

So that returns the first character from the end of the string.

41:12

Let's do on this program, you will see we'll get g.

41:16

There you go.

41:18

Using a similar syntax, you can slice strings. Let me show you.

41:23

So I'm going to duplicate this line and remove negative one.

41:28

Now let's say we want to extract the first three characters in this string.

41:33

So here we need two indexes.

41:35

The start index, colon, the end index.

41:39

So this will return a new string that contains the first three characters in this course variable.

41:46

That will be p, y, and t.

41:49

So the index of these characters are zero, one, and two.

41:53

So that means the character at the end index is not included, okay?

41:59

Let's run the program and make sure we get the right result.

42:02

There you go, p, y, t.

42:05

Now what if we don't include the end index?

42:08

What do you think we're going to get?

42:10

It's common sense.

42:12

We start from index zero and go all the way to the end of the string.

42:17

So this will return a new string that is exactly the same as the original string.

42:22

Let's take a look.

42:24

So we get Python programming.

42:28

Now what if we don't include the start index, but include the end index?

42:34

What do you think we're going to get?

42:36

Once again, it's common sense.

42:38

So by default, Python will put zero here, so it will start from the beginning of the string.

42:43

So when I run this program, we should get p, y, t, one more time.

42:47

There you go.

42:49

And finally, as the last example, if we don't include the start and the end index,

42:55

this will return a copy of the original string.

42:58

Let's look at this.

43:00

So we get Python programming.

43:03

Now you don't have to memorize any of these.

43:06

Just remember, we use the length function to get the length of a string.

43:10

We use bracket notation to get access to a specific element or a specific character.

43:16

And we use this notation to slice a string.

43:25

So we have this string here, Python programming.

43:28

Now let's say we want to put a double code in the middle of this string.

43:33

There is a problem here.

43:35

Python interpreter sees this second string as the end of the string.

43:40

So the rest of the code is meaningless and invalid.

43:44

How do we solve this problem?

43:46

Well, there are two ways.

43:48

One way is to use single codes for our string.

43:53

And then we can use a double code in the middle of the string.

43:56

But what if for whatever reason, perhaps for being consistent in our code?

44:01

We decided to use double codes.

44:04

How can we add another double code in the middle of this string?

44:08

Well, we can prefix this with a backslash.

44:13

Backslash in Python strings is a special character.

44:16

We have a jargon for that called escape character.

44:20

We use it to escape the character after.

44:24

Let me show you what I mean.

44:26

So let's print this course and run this program.

44:31

What's going on here?

44:33

We don't have the backslash because we use that to escape this double code

44:38

and basically displayed here.

44:41

So backslash is on escape character.

44:44

And backslash double code is on escape sequence.

44:48

In Python strings we have a few other escape sequences that you should be aware of.

44:53

Let me show you.

44:55

So in Python we use a high sign to indicate a comment.

44:59

A comment is like additional note that we add to our program.

45:03

It's not executed by Python interpreter.

45:06

So here are the escape sequences.

45:09

You have seen backslash double code.

45:11

We also have backslash single code.

45:15

So we can use that to add a single code here.

45:19

Let's run the program.

45:21

Here it is beautiful.

45:23

We also have double backslash.

45:26

So if you want to include a backslash in your strings,

45:30

you should prefix it with another backslash.

45:33

Let me show you.

45:34

So when we run this we get Python 1 backslash for programming.

45:39

And finally we have backslash n, which is short for new line.

45:44

So now if I add a backslash n here, see what we get.

45:51

We get a new line after Python, so programming will end up on the second line.

45:57

So these are the escape sequences in Python.

46:05

Here we have two variables first and last.

46:08

Let's say we want to print my full name on the console.

46:12

So we can define another variable full set it to first,

46:17

then concatenate it with a space.

46:21

And one more time concatenated with last.

46:25

Now when we print full, we get my full name on the console.

46:31

Beautiful.

46:32

Now this approach are using concatenation to build a string is okay,

46:37

but there is a better and newer approach.

46:40

We can use formatted strings.

46:42

So here we can set full to this string and prefix it with an F,

46:48

which can be lower case or upper case.

46:51

This formatted string doesn't have a constant value like these two strings here.

46:56

It's actually an expression that will be evaluated at runtime.

47:01

So here we want to add our first name.

47:04

We use curly braces to print the value of the first variable.

47:09

After that we add a space and then we add curly braces one more time

47:14

to print the last name.

47:17

So at runtime this expression will be evaluated.

47:20

What we have in between curly braces will be replaced at runtime.

47:26

Now let's run this program one more time.

47:29

We get the exact same result.

47:32

Just be aware that you can put any valid expressions in between curly braces.

47:38

So earlier you learned about the built in land function.

47:42

We can call land here to get the lengths of this string.

47:47

Let's run this program one more time.

47:49

So we get four.

47:51

We can also replace last with an expression like this two plus two.

47:56

Let's run this program we get four and four.

48:00

So when using formatted strings you can put any valid expressions in between curly braces.

48:08

In this lecture we're going to look at a few useful functions available to work with strings.

48:18

So earlier you learned about this built in land function.

48:22

This function is general purpose so it's not limited to strings.

48:26

Later I will show you how to use this function with other kind of objects.

48:30

But in Python we have quite a few functions that are specific to strings.

48:35

Let me show you.

48:36

So here if we type course dot see all these are functions available on strings.

48:46

Now in precise terms we refer to these functions as methods.

48:51

This is a term in object-oriented programming that you will learn about later in the course.

48:56

For now what I want you to take away is that everything in Python is an object and objects have functions.

49:04

We call methods that we can access using the dot notation.

49:09

So here course is an object.

49:11

We use the dot notation to access its functions or more accurately methods.

49:16

Let's take a look at a few of these methods.

49:19

We have upper to convert a string to upper case.

49:22

Now let's print this and run the program.

49:27

Here is what we get beautiful.

49:29

Now note that the methods that you call here return a new string.

49:33

So the original string is not affected.

49:36

Let me show you.

49:37

So print course run the program one more time.

49:41

Look this is our original string right?

49:44

So course dot upper returns a new string a new value.

49:49

We can store it in a variable like course on the light capital like this.

49:56

Now to keep this demo simple and consistent I'm going to revert this back and use a print statement.

50:02

We also have the lower method to convert a string to lower case.

50:08

We also have title which will capitalize the first letter of every word.

50:15

So if our string was like this.

50:19

When we call the title method we get Python programming as you see here.

50:25

Okay.

50:27

Another useful method is strip and we use it to trim any white space at the beginning or end of a string.

50:34

This is particularly useful when we receive input from the user.

50:38

Let me show you.

50:39

So let's imagine the user entered a couple of white spaces at the beginning of the string.

50:46

When we call course dot strip those white spaces will be removed.

50:52

Take a look.

50:53

So note that in the first three examples we have those white spaces but in the last one it is removed.

51:00

So strip remove the white space from both the beginning and end of a string.

51:05

We also have L strip which is short for left strip and R strip which is short for right strip.

51:12

So it will remove the white space from the end of a string.

51:15

If you want to get the index of a character or a sequence of characters in your string,

51:21

you should use the find method and we'll show you.

51:24

So of course that find.

51:28

So as an argument here we pass another string.

51:32

We can pass a character or a series of characters.

51:37

Let's find the index of pro.

51:40

Round the program.

51:42

So the index of pro is 9.

51:44

So if you start from zero here all the way to 9 this is the index of pro.

51:50

Okay.

51:51

Now as I told you before python is a case sensitive language.

51:55

So if I pass a capital P here obviously we don't have these exact characters in our string.

52:02

So let's see what we get.

52:05

We get negative one.

52:07

That means this string was not found in the original string.

52:11

Another useful method is replace.

52:14

So we call replace.

52:17

With this we can replace a character or a sequence of characters with something else.

52:22

So let's say we want to replace all lowercase piece with j.

52:27

With this we get jth on geogramming.

52:32

Whatever that means.

52:34

And finally if you want to check for the existence of a character or a sequence of characters in your string,

52:41

you can use the in operator.

52:44

Let me show you.

52:45

So this is an expression.

52:47

Realize an expression like this.

52:49

Pro in course.

52:52

So this is an expression as I told you before.

52:55

An expression is a piece of code that produces a value.

52:59

So this expression checks to see if we have pro in course.

53:03

The difference between this expression and calling the fine method is that the fine method returns the index of these characters in our string.

53:13

But as this expression returns a Boolean.

53:16

So it's a true or false.

53:18

Let me show you.

53:19

So we run the program.

53:21

We get the Boolean true.

53:24

And finally we have the not operator.

53:27

And we use that to see if our string does not contain a character or a sequence of characters.

53:34

So let's change this to Swift.

53:40

Not in course.

53:42

When this expression is evaluated, what do you think we're going to get?

53:46

Well, we don't have Swift in this string.

53:50

So not in will return true.

53:53

Let's take a look.

53:55

There you go.

53:57

So these are the useful string methods.

54:00

Next we'll look at numbers.

54:02

In Python, we have three types of numbers.

54:10

Two of these we have already seen before.

54:12

They are integers and floats.

54:16

We also have complex numbers.

54:19

So complex numbers in math are in the form A plus B i.

54:24

Where i is the imaginary number?

54:26

If you're not familiar with this concept,

54:29

or this is something that it uses a lot in mathematics and electrical engineering.

54:34

If you want to use Python to build web applications,

54:37

you're never going to use complex numbers.

54:39

But let me quickly show you the syntax for representing complex numbers.

54:44

Instead of i, we use j.

54:46

So here is an example.

54:48

1 plus 2 j.

54:50

So x now is a complex number.

54:53

And by the way, as I told you before,

54:55

this is just a comment or an additional note in our program.

54:59

When we run this program, anything after this high sign will be ignored.

55:04

So these are the three types of numbers we have in Python.

55:07

For all these types of numbers,

55:09

we have the standard arithmetic operations that we have in math.

55:14

Let me show you.

55:15

So we have addition,

55:18

subtraction,

55:20

multiplication,

55:22

division.

55:23

But we actually have two different types of divisions.

55:26

Let me show you.

55:27

First, let's run this program.

55:29

So with this division operator,

55:31

which is a slash,

55:33

we get a floating point number.

55:35

If you want an integer,

55:37

you use double slashes.

55:39

Let me show you.

55:41

So double slash,

55:43

run the program.

55:44

We get three.

55:46

Okay?

55:47

We also have modules,

55:50

which is the remainder of a division.

55:52

And finally,

55:54

exponent,

55:55

which is left to the power of right.

55:58

So 10 to the power of three will be a thousand.

56:01

These are the standard arithmetic operators.

56:04

Now for all these operators,

56:06

we have a special operator called augmented assignment operator.

56:11

Let me show you.

56:12

So let's imagine we have X set to 10.

56:16

We want to increment X by,

56:19

let's say, three.

56:21

We can write an expression like this.

56:23

X equals X plus three.

56:26

Or we can use an augmented assignment operator.

56:29

That is a little bit shorter.

56:31

So we write X plus equal three.

56:35

These two statements are exactly the same.

56:38

Now here I'm using addition as an example.

56:41

You can use any of these operators here.

56:44

Next, I'm going to show you some useful functions

56:47

to work with numbers.

56:50

In this lecture,

56:54

we're going to look at a few useful functions to work with numbers.

56:58

So we have this built-in function round for rounding a number.

57:03

So if we pass 2.9 here and print the result,

57:08

we'll get three.

57:10

We have another useful built-in function called ABS,

57:14

which returns the absolute value of a number.

57:17

So if you pass negative 2.9 here, we'll get positive 2.9.

57:24

That's technically we have only a handful of built-in functions

57:28

to work with numbers.

57:30

If you want to write a program that involves complex mathematical calculations,

57:35

you need to use the math module.

57:38

And module is like a separate file with some Python code.

57:42

So in Python, we have this math module,

57:45

which includes lots of mathematical functions for working with numbers.

57:49

But we need to import this module so we can use it.

57:52

On the top, with type, import, math.

57:57

Now math in this program is an object.

58:00

So we can use the dot notation to see all the functions

58:05

or more accurately, all the methods available in this object.

58:10

As an example, we have math.seal for getting the ceiling of a number.

58:16

So if you pass 2.2 here and run this program, we get three.

58:24

Now in this math module, we have lots of functions.

58:27

Let me show you how to find the completeness.

58:30

Here on Google, search for Python 3,

58:34

make sure to add the version number, math module.

58:40

On this page, you can see all the functions in the math module.

58:45

So in this lecture, we looked at math.seal.

58:49

We also have math.copySign, Fabs, and so on.

58:53

As an exercise, I encourage you to play with a couple of functions in this module.

59:03

Alright, now let's take a look at another useful built-in function in Python.

59:08

We use the input function to get input from the user.

59:12

As an argument, we pass a string.

59:15

This will be a label that will be displayed in the terminal.

59:18

You will see that in a second.

59:20

So let's add x colon.

59:23

Now this function returns a string.

59:25

So we can store it in this variable.

59:29

Now let's imagine that y should be x plus 1.

59:34

Save the changes.

59:36

Now don't run this program using the code runner extension

59:40

because code runner by default runs your program in the output window,

59:44

which is read only.

59:45

So you won't be able to enter a value.

59:48

So open up the terminal using control and backspace.

59:52

Once again, if you're on Windows, type Python,

59:55

if you're on Mac or Linux, type Python 3, and then app.py.

01:00:00

So here's our label.

01:00:02

Let's enter a value like 1.

01:00:04

We got an error, type error.

01:00:07

What is going on here?

01:00:09

Well, when we receive input from the user,

01:00:12

this input always comes as a string.

01:00:15

So this expression at runtime will look like this.

01:00:19

String 1 plus 1.

01:00:22

Note that the number 1 is different from string 1 because these are two different types.

01:00:27

Now when Python sees this expression, it doesn't know what to do.

01:00:32

Because two objects can be concatenated if there are of the same type.

01:00:36

So here we need to convert this string 1 to a number.

01:00:40

In Python, we have a few built-in functions for type conversion.

01:00:45

We have int for converting a number to an integer.

01:00:49

We have float, we have bull and stir or string.

01:00:56

Now in this case, we don't need to convert x to a string

01:00:59

because x is already a string.

01:01:01

If you don't believe me, let me show you.

01:01:03

So I'm going to comment out these few lines.

01:01:07

Now let's print type of x.

01:01:12

So type is another built-in function.

01:01:15

We pass an object as an argument and it returns its type.

01:01:19

Also, I'm going to comment out this line,

01:01:22

because that's the bad boy.

01:01:23

We don't want to execute this.

01:01:25

Save the changes.

01:01:26

Back in the terminal,

01:01:27

let's run this program one more time.

01:01:29

Enter one.

01:01:31

Look.

01:01:32

This is what the type function returns.

01:01:34

Now don't worry about the class.

01:01:36

We'll talk about classes later in the course.

01:01:38

So the type of x is a stir or string.

01:01:43

So let's delete this line.

01:01:46

To fix this problem, we need to convert x to an integer.

01:01:51

And then we can print both x and y using a formatted string.

01:01:56

Remember?

01:01:57

So we add an f, close.

01:01:59

Now here we add a label like x.

01:02:01

Then we'll add a field.

01:02:04

So here we want to print the value of x variable.

01:02:08

After that, we add some more text.

01:02:11

And finally, we want to print the value of y.

01:02:15

Let's run this program one more time.

01:02:18

So here in the terminal,

01:02:20

let's enter one.

01:02:22

And here's the result.

01:02:23

x is one and y is two.

01:02:25

Beautiful.

01:02:26

Now all these built-in functions are self-explanatory.

01:02:30

The only tricky one is bull.

01:02:32

Because in Python,

01:02:33

we have this concept of truthy and falsy values.

01:02:37

These are values that are not exactly a Boolean true or false,

01:02:41

but they can be interpreted as a Boolean true or false.

01:02:45

So here are the falsy values in Python.

01:02:50

M2 strings are considered falsy,

01:02:52

so they're interpreted as a Boolean false.

01:02:55

Number zero is also falsy.

01:02:57

We have an object called non,

01:02:59

which represents the absence of a value.

01:03:02

We'll look at this later in the course.

01:03:04

So whenever we use these values in a Boolean context,

01:03:08

we'll get false.

01:03:10

Anything else will be true.

01:03:12

Let me show you a few examples.

01:03:15

So in this interactive shell in Python,

01:03:17

let's convert number zero to bull.

01:03:21

That's falsy, so we get false.

01:03:23

What about bull of one?

01:03:26

We get true.

01:03:27

If we pass a negative number,

01:03:29

we'll also get true.

01:03:31

If we pass a number larger than one,

01:03:34

like five, we still get true.

01:03:36

So we only get false.

01:03:37

Let me try to convert zero to a Boolean.

01:03:40

Now with strings,

01:03:41

I told you that an empty string is falsy.

01:03:44

So here we'll get false.

01:03:47

Anything else is true.

01:03:49

So even if I have a string that is false,

01:03:53

we'll get true.

01:03:55

Because this is not an empty string.

01:03:57

It's a string with a few characters.

01:03:59

That's why it's a value-it-a-stru.

01:04:06

All right. Once again,

01:04:07

it's time for another quiz.

01:04:09

Let's see if you've been really paying attention to this tutorial.

01:04:12

So here's the first question.

01:04:13

What are the built-in primitive types in Python?

01:04:21

We have strings, numbers, and Boolean ads.

01:04:25

Numbers can be integers, floats, or complex numbers.

01:04:30

Here's the second question.

01:04:32

You have this variable, fruit, set to apple.

01:04:35

What do you think we will see on the terminal

01:04:37

when we print fruit of one?

01:04:44

Well, using screw brackets,

01:04:46

we can access individual characters.

01:04:48

The index of the first character is zero.

01:04:51

So this expression returns the second character, which is p.

01:04:55

What if we add a colon and negative one here?

01:05:04

Well, using the same text, we can slice a string.

01:05:07

Our start index is one,

01:05:09

and our end index is negative one,

01:05:11

which refers to the first character from the end of the string.

01:05:15

Now, when slicing a string,

01:05:17

the character at the end index, or negative one,

01:05:20

is not included.

01:05:22

So with this expression,

01:05:23

we'll get all the characters starting from the second character,

01:05:27

which is p, all the way until we get to e.

01:05:30

So the result of this expression is ppl.

01:05:34

Here's another question.

01:05:36

What is the result of this expression?

01:05:42

Well, this is what we call the modulus operator,

01:05:46

and it returns the remainder of a division,

01:05:49

which is in this case one.

01:05:51

And finally, the last question.

01:05:54

What do you think we will see when we print

01:05:56

bull of false?

01:06:02

Well, earlier I told you about false values in Python.

01:06:06

So number zero, an empty string,

01:06:09

and the non-object is our all-false values.

01:06:12

Anything that is not false is considered true C.

01:06:15

Here we have a string that has five characters.

01:06:18

It doesn't matter what those characters are.

01:06:20

This is not an empty string.

01:06:22

So it's not false C.

01:06:24

It's true C.

01:06:25

So when we convert it using the bull function,

01:06:28

we'll get the bullion true.

01:06:30

And this brings us to the end of the section.

01:06:32

In the next section, you're going to learn

01:06:34

the fundamentals of computer programming.

01:06:37

I hope you have enjoyed this section,

01:06:38

and thank you for watching.

01:06:47

We're going to start this section by exploring

01:06:49

comparison operators.

01:06:51

We use comparison operators to compare values.

01:06:54

Here are a few examples.

01:06:55

So 10 is greater than 3.

01:06:58

We get true.

01:06:59

So what we have here is a bullion expression.

01:07:03

Because when this expression is evaluated,

01:07:05

we'll get a bullion value that is true or false.

01:07:08

Here is another example.

01:07:10

10 is greater than or equal to 3.

01:07:13

Once again, we get true.

01:07:15

We also have less than, so 10 is less than 20.

01:07:19

We have less than or equal to.

01:07:22

Here's the equality operator.

01:07:24

So 10 is equal to 10.

01:07:26

What about this expression?

01:07:29

What do you think we're going to get?

01:07:31

We get false.

01:07:32

Because these values have different types,

01:07:35

and they're stored differently in the computer's memory.

01:07:38

And finally, we have the not equal operator.

01:07:42

So now with this expression, we should get true.

01:07:45

Beautiful.

01:07:46

We can also use these comparison operators with strings.

01:07:50

Let me show you.

01:07:51

So we can check to see if bag is greater than apple.

01:07:56

We get true because when we sort these two words,

01:08:00

bag comes after, so it's considered greater.

01:08:03

Now what about this one?

01:08:05

Bag equals capital bag.

01:08:08

We get false.

01:08:09

Here's the reason.

01:08:11

Every character you see here has a numeric representation in programming.

01:08:15

Let me show you.

01:08:16

So we have this built-in function called Ord.

01:08:19

Don't worry about memorizing this,

01:08:21

because you probably never going to use this in the future.

01:08:24

But let me show you the numeric representation of the letter B.

01:08:28

So that is 98.

01:08:30

In contrast, capital B is represented as 66.

01:08:35

That is the reason these two strings are not equal.

01:08:39

So these are the comparison operators in Python.

01:08:42

Next, we'll look at conditional statements.

01:08:50

In almost every program, there are times you need to make decisions.

01:08:54

And that's when you use an if statement.

01:08:57

Here's an example.

01:08:58

Let's say we have a variable called temperature.

01:09:01

We studied to 35.

01:09:03

Now if temperature is greater than 30,

01:09:06

perhaps we want to display a message to the user.

01:09:09

So we use an if statement.

01:09:11

If after if we add a condition,

01:09:14

which is basically a Boolean expression,

01:09:16

an expression that produces a Boolean value.

01:09:19

So if temperature is greater than 30,

01:09:23

here we have a Boolean expression.

01:09:25

If this expression evaluates to true,

01:09:28

the following statements will be executed.

01:09:30

Let me show you.

01:09:31

Now here's the important part that a lot of beginners miss.

01:09:35

When you use an if statement,

01:09:37

you should always terminate your statement with a colon.

01:09:41

Now let's see what happens when I press enter.

01:09:44

Our cursor is indented.

01:09:46

So here we have two white spaces.

01:09:49

This is very important because using these indentations,

01:09:53

Python interpreter will know what statements should be executed

01:09:57

if this condition is true.

01:09:59

Here we want to print a message like it's warm.

01:10:03

We can print another message as well.

01:10:07

Drink water.

01:10:08

So we can have as many statements as we want here.

01:10:11

As long as they are indented,

01:10:13

they belong to this if block.

01:10:16

Now when we finish here,

01:10:18

we should remove indentation to indicate the end of this if block.

01:10:21

So here we can add a print statement with a message like done.

01:10:26

This statement will always be executed,

01:10:29

whether this condition is true or not.

01:10:32

Now note that when I save the changes,

01:10:35

this indentation you see here is going to be doubled up.

01:10:38

Take a look.

01:10:39

Save.

01:10:40

There you go.

01:10:41

So when we save the changes,

01:10:43

auto-pepp eight reformats are code

01:10:45

and uses four white spaces for indentation.

01:10:48

So one, two, three, four.

01:10:51

It uses four white spaces because that's what pep eight recommends.

01:10:55

All right.

01:10:56

Now let's run this program.

01:10:58

So because temperature is greater than 13,

01:11:01

we see the first two messages

01:11:03

and we see the done message regardless.

01:11:06

So if I change the temperature to let's say 15

01:11:09

and run the program one more time,

01:11:12

look, this done message is executed

01:11:15

whether our condition is true or not.

01:11:18

So pay great attention to these indentations.

01:11:21

That's one of the issues I see in beginners code.

01:11:24

Let's say they want both these print statements

01:11:26

to be executed if the condition is true.

01:11:29

Accidentally, they remove the indentation

01:11:32

on the fourth line.

01:11:33

And that's why their program doesn't work as they expect.

01:11:36

So be careful about this.

01:11:38

Now what if you want to have multiple conditions?

01:11:42

We use an L if statement.

01:11:44

So L if that is short for L's if.

01:11:48

Here we can add another condition.

01:11:50

Another expression.

01:11:51

So temperature is greater than 20 once again.

01:11:55

Column.

01:11:56

Enter.

01:11:57

Now by default here,

01:11:59

VS code is using two white spaces.

01:12:01

So don't worry about this.

01:12:02

As soon as you save the changes,

01:12:04

those two white spaces will be converted to four white spaces.

01:12:08

So let's print a different message.

01:12:11

It's nice.

01:12:13

Save the changes.

01:12:15

Now look, all these lines are indented consistently.

01:12:19

You can have as many L if statements as you want.

01:12:22

And optionally, you can also have an L statement.

01:12:26

So if none of the previous conditions are true,

01:12:29

then what you have in the L's block will be executed.

01:12:33

Once again, we add the colon,

01:12:35

annotation, print.

01:12:38

Here we can add a message like it's called.

01:12:42

Save the changes.

01:12:43

In this case, temperature is 15.

01:12:45

So none of these two conditions will be true.

01:12:49

And we will see it's called.

01:12:51

Let's run the program.

01:12:53

There you go.

01:13:00

In this lecture, I'm going to show you a technique for writing clean our code.

01:13:04

So let's say we're building an application for university.

01:13:07

And if you want to check to see if the person who's applying for this university program is eligible or not.

01:13:14

So we start by defining a variable called age.

01:13:18

Set it to 22.

01:13:20

Now, if age is greater than or equal to 18,

01:13:24

colon, print, eligible.

01:13:29

Remove the indentation, else, colon, print, not eligible.

01:13:36

Let's run the program.

01:13:38

Make sure it works beautiful.

01:13:41

Now, there is nothing wrong in this piece of code,

01:13:43

but I want to show you a cleaner way to achieve the same result.

01:13:47

Instead of having a print statement here,

01:13:50

we can define a variable like message

01:13:53

and set it to this string.

01:13:56

That is the first step.

01:13:58

So message equals this string.

01:14:01

And then we will print this message.

01:14:05

Now, when you have an if L statement with this structure,

01:14:09

where you're basically assigning a value to a variable,

01:14:12

you can rewrite this in a simpler way.

01:14:15

So, this is how it works.

01:14:18

All we want to do over this field lines is to assign a value to this message variable, right?

01:14:24

So we start with message.

01:14:26

We set it to eligible if age is greater than or equal to 18,

01:14:32

else we set it to not eligible.

01:14:36

This statement is almost like plain English.

01:14:40

So what we have online seven is exactly equivalent

01:14:44

to these four lines of code.

01:14:46

Delete, save the changes, run the program.

01:14:50

You can see this person is eligible.

01:14:52

If I change the age to 12 and run the program,

01:14:56

we get not eligible.

01:15:00

So what we have here is called turnery operator.

01:15:09

In Python, we have three logical operators

01:15:12

and we use these operators to model more complex conditions.

01:15:17

So these operators are and or and not.

01:15:22

Let's see a real word example of using these operators.

01:15:25

So imagine we're building an application for processing loans.

01:15:28

So we need to variables high income.

01:15:32

We can set this to true and good online credit with set it to true.

01:15:39

Now here's the condition we want to implement.

01:15:42

If the applicant has high income and good credit square,

01:15:47

then there are eligible for the loan.

01:15:50

So if high income and good credit,

01:15:55

we had the colon and print eligible.

01:15:59

Now note that here I have not compared the value of this variable with true.

01:16:05

That is one of the issues I see in a lot of beginners code.

01:16:08

This is redundant and unprofessional because high income is a Boolean.

01:16:13

So it's either true or false.

01:16:15

We don't need to compare true with true.

01:16:18

So if this condition is true and this second condition is true,

01:16:23

then we will print eligible in the terminal.

01:16:27

So save the changes and run the program.

01:16:30

Obviously this person is eligible.

01:16:33

However, if one of these conditions is false,

01:16:37

we will not see eligible in the terminal.

01:16:39

So let's add an L statement here and print not eligible.

01:16:47

Run the program.

01:16:49

We see not eligible.

01:16:51

So this is how the and operator works.

01:16:54

With and operator, if both conditions are true,

01:16:57

the result will be true.

01:16:59

In contrast with the or operator,

01:17:02

as long as at least one of the conditions is true,

01:17:05

the result will be true.

01:17:06

So if I replace and with or here,

01:17:10

we should see eligible in the terminal.

01:17:13

Let's run it one more time.

01:17:15

There you go.

01:17:16

So these are the and or operators.

01:17:19

Now let's take a look at an example of the not operator.

01:17:22

So I'm going to define another variable student.

01:17:25

Set it to true.

01:17:27

Tape it early.

01:17:28

I'm going to remove this expression and simplify it.

01:17:31

We'll come back to this later.

01:17:33

So let's say if the person is eligible,

01:17:36

if they are not a student.

01:17:38

The not operator basically inverses the value of a Boolean.

01:17:42

So in this case, student is true.

01:17:45

When we apply the not operator, the result will be false.

01:17:49

So in this case, our condition will be false.

01:17:51

And that's why this print statement will not be executed.

01:17:55

Let me show you.

01:17:56

So save run the program.

01:17:59

They're not eligible.

01:18:01

If student was false.

01:18:03

When we apply the not operator will get true.

01:18:06

So our condition will be true and we'll see it eligible.

01:18:09

Let's run it one more time.

01:18:11

There you go.

01:18:13

With these operators, we can model even more complex conditions.

01:18:17

Here is an example.

01:18:19

A person can be eligible if they have either high income or good credit.

01:18:25

And they should not be still that.

01:18:28

Let me show you how to implement this condition.

01:18:30

So if high income or good credit,

01:18:35

we won't at least one of these conditions to be true.

01:18:39

So we put these in parenthesis.

01:18:43

We want to separate these from the other condition, which is not a student.

01:18:47

Now the result of this should be true, which means at least one of these conditions should be true.

01:18:53

After that, we'll add and not student.

01:18:58

And finally call.

01:19:00

So with these operators, you can model all kinds of real words scenarios.

01:19:10

So here's the example from the last lecture.

01:19:13

A person is eligible for a loan if they have high income and good credit.

01:19:19

And they are not still that.

01:19:22

Now one thing you need to know about these Boolean operators is that they are short circuit.

01:19:27

What do they mean by that?

01:19:29

Well, when Python interpreter wants to evaluate this expression,

01:19:33

it starts from the first argument.

01:19:36

If this is true, it continues the evaluation to see if the second argument is also true.

01:19:42

So it continues the evaluation all the way to the end of this expression.

01:19:47

However, as soon as one of these arguments is false, the evaluation stops.

01:19:52

Let me show you what I mean.

01:19:54

So if I change high income to false, when Python interpreter sees this expression,

01:20:01

it starts here.

01:20:02

It knows that high income is false,

01:20:04

so it doesn't matter what comes after the result of this entire expression will always be false

01:20:11

because at least one of the arguments or one of the operands is false.

01:20:16

This is what we call short circuiting.

01:20:18

Just like the short circuit concept we have in electronics.

01:20:22

So the evaluation stops as soon as one of these arguments,

01:20:27

the evaluates to false.

01:20:29

We have the same concept with the OR operator.

01:20:32

So if I change these and operators to OR, let's see what happens.

01:20:38

With the OR operator, we know that at least one of the arguments should be true.

01:20:43

So the evaluation stops as soon as we find an argument that evaluates to true.

01:20:48

In this case, when Python interpreter evaluates to this expression,

01:20:52

it sees that high income is false, so it continues the evaluation

01:20:56

hoping that the next argument will be true.

01:20:59

Here, good credit is true, so evaluation stops,

01:21:03

and the result of this entire expression will be true.

01:21:07

So in Python, logical operators are short circuit.

01:21:17

In this lecture, I'm going to show you how to chain comparison operators.

01:21:21

This is a very powerful technique for writing clean code.

01:21:24

Here is an example.

01:21:25

Let's say we want to implement a rule that says age should be between 18 and 65.

01:21:32

Here's how we can implement it.

01:21:35

So we define a variable like age set it to 22.

01:21:38

Now, if age is greater than or equal to 18,

01:21:42

and age is less than 65, then we print eligible.

01:21:49

Now, here's a question for you.

01:21:51

How do we write this rule in math?

01:21:53

We can write it like this.

01:21:57

Well, more accurately, we should have an equal sign here.

01:22:01

So age should be between 18 and 65.

01:22:05

This is how we write this rule in math.

01:22:07

Now, I've got some good news for you.

01:22:09

We can write the exact same expression in Python.

01:22:12

So I'm going to move this up, put an if statement here.

01:22:18

Line 4 and line 3 are exactly equivalent.

01:22:22

But as you can see, line 4 is cleaner and easier to read.

01:22:26

So let's get rid of line 3.

01:22:29

This is what we call chaining comparison operators.

01:22:39

Alright, here's a little quiz for you.

01:22:41

I want you to pause the video and think about this quiz for 10 to 20 seconds.

01:22:46

What do you think we'll see on the terminal when we run this program?

01:22:50

So pause the video, figure out the answer when you're ready.

01:22:54

Come back continue watching.

01:22:58

Alright, let's see what happens when we run this program.

01:23:01

First, we get this if statement.

01:23:03

In this case, we're comparing two different objects for equality.

01:23:07

And these objects have different types.

01:23:09

We have a number compared with this string.

01:23:12

So number 10 and string 10 are not equal.

01:23:15

That is why A will not be printed on the terminal.

01:23:19

So the control moves to the elephant part.

01:23:22

Here we have two Boolean expressions.

01:23:25

Here's the first one. Here's the second one.

01:23:28

And they are combined using the logical end.

01:23:31

So if both these expressions are evaluated to true,

01:23:35

then this entire expression will be true and we will see beyond the terminal.

01:23:40

Let's see if both these expressions are evaluated to true.

01:23:44

Here's the first part.

01:23:46

Back is greater than apple.

01:23:48

That is true because when we sort this word,

01:23:51

back comes after apple.

01:23:53

But look at the second part.

01:23:55

This expression is evaluated to false because back is not greater than cat.

01:24:00

So when we apply the logical end between true and false,

01:24:04

the result will be false.

01:24:06

That is why this statement will not be executed.

01:24:09

So to control moves to the else part.

01:24:12

And when we run this program,

01:24:14

the letter C will be printed on the terminal.

01:24:22

There are times that we may want to repeat a task a number of times.

01:24:26

For example, let's say we send a message to a user.

01:24:29

If the message cannot be delivered,

01:24:32

perhaps we want to retry three times.

01:24:34

Now for simplicity, let's imagine this print statement

01:24:38

is equivalent to sending a message.

01:24:41

In a real world program,

01:24:43

to send a message to a user,

01:24:45

we have to write five to ten lines of code.

01:24:47

Now if you want to retry three times,

01:24:49

we don't want to repeat all that code.

01:24:51

That is ugly.

01:24:52

That's when we use a loop.

01:24:54

We use loops to create repetition.

01:24:57

So here is how it works.

01:24:59

We start with four,

01:25:02

number in.

01:25:03

We have a built-in function called range.

01:25:05

Now how many times we want to repeat this task?

01:25:08

Let's say three times.

01:25:10

So we call range and pass three as an argument.

01:25:13

Now similar to our if statements,

01:25:15

we need to terminate this line with a colon.

01:25:19

Enter, we get indentation.

01:25:21

So in this block,

01:25:23

we can write all the statements that should be repeated three times.

01:25:27

Let's do a print a message like attempt.

01:25:30

Save the changes.

01:25:32

Run the program.

01:25:34

So we have attempt printed three times beautiful.

01:25:37

Now what is this number?

01:25:39

Let's take a look.

01:25:40

It's a variable of type integer.

01:25:43

So let's pass it as the second argument to the print function.

01:25:48

Number.

01:25:49

Run the program.

01:25:50

This is what we get.

01:25:52

012.

01:25:54

So here we have a four loop.

01:25:56

This four loop is executed three times.

01:25:59

In each iteration, number will have a different value.

01:26:02

Initially it will be zero.

01:26:04

In the second iteration it will be one.

01:26:06

And finally in the last iteration it will be two.

01:26:09

Now here we can do something fun.

01:26:11

We can add.

01:26:13

Want to this.

01:26:15

Run the program.

01:26:16

I now the messages that the print are kind of more meaningful or more user-friendly.

01:26:21

Like attempting number one, attempting number two and so on.

01:26:25

We can take this to the next level.

01:26:27

So we can pass another argument.

01:26:29

Here I'm going to add an expression.

01:26:31

One more time.

01:26:32

Number plus one.

01:26:33

So we'll get one to three.

01:26:35

Now I want to put this expression in parentheses.

01:26:38

So let's select this.

01:26:40

Put it in parentheses.

01:26:42

And then multiply it by a dot.

01:26:46

So here we have a string that is multiplied by a number.

01:26:50

The result will be that string repeated that number of times.

01:26:54

Let's take a look.

01:26:55

So run the program.

01:26:57

See?

01:26:58

That's pretty cool, isn't it?

01:27:00

Now let me show you one more thing before we finish this lecture.

01:27:03

As you saw, this range function generates numbers.

01:27:06

Starting from zero all the way up to this number here.

01:27:09

But it doesn't include this number.

01:27:11

Here we can pass another argument.

01:27:13

Say start from one and finish before four.

01:27:18

With this change, we don't need to add one to number every time.

01:27:23

Because in the first iteration, this number variable will be set to one.

01:27:27

So we can simplify our code and make it cleaner.

01:27:31

Let's run it one more time.

01:27:32

We get the exact same result.

01:27:35

We can also pass a third argument as a step.

01:27:38

So I'm going to change the second argument to 10 and pass two as a step.

01:27:44

Look at the result.

01:27:46

These are the numbers we get.

01:27:48

One, three, five and so on.

01:27:50

So pretty useful.

01:27:51

You're going to use this function a lot in real-world applications.

01:28:00

Continuing with the example from the last lecture.

01:28:02

Let's imagine the scenario where after the first attempt,

01:28:05

we can successfully send the message.

01:28:07

In that case, we want to jump out of this loop.

01:28:10

We don't want to repeat this task of sending a message three times.

01:28:15

Let me show you how to implement this.

01:28:18

So in this demo, I'm going to simulate the scenario where we can successfully send a message.

01:28:23

So we define a variable, successful, and set it to true.

01:28:29

Now here, after this print statement, we'll have an if statement.

01:28:35

If successful, colon, then perhaps we can print successful.

01:28:42

Now here we want to jump out of this loop.

01:28:45

For that, we use the break statement.

01:28:47

Let's try this program and see what happens.

01:28:50

So there you go.

01:28:52

After the first attempt, we're successful and there are no more attempts.

01:28:57

So once again, I want you to take great attention to the indentation here,

01:29:02

because that's one of the common issues amongst beginners.

01:29:05

So here's our four loop.

01:29:07

These two lines are indented with four spaces, and they belong to our four loop.

01:29:13

In every iteration, these two lines will be executed.

01:29:16

Now, when we get to line four, if this condition is true, then these two lines will be executed.

01:29:24

Because both these lines are indented below this if statement.

01:29:29

Now let's take this program to the next level.

01:29:32

What if we attempt three times?

01:29:34

I still cannot send an email.

01:29:36

Perhaps we want to display a different message to the user.

01:29:39

We say, hey, we try three times why it didn't work.

01:29:42

So I'm going to change successful to false.

01:29:47

Now, at the end, here we can add an L statement.

01:29:51

This is what we call a four L statement.

01:29:54

What we put under this L statement will only be executed if this loop completes without an early termination.

01:30:01

So if we never break out of this loop, then the L statement will be executed.

01:30:07

So here we can print a message like attempt at three times and failed.

01:30:13

So run the program.

01:30:17

See what we get?

01:30:19

Three attempts followed by this message attempt at three times and failed.

01:30:24

In contrast, if we change successful to true,

01:30:28

because we terminate this loop using this break statement, what we have in the L's block will not be executed.

01:30:35

Take a look.

01:30:36

Run the program.

01:30:37

We have one attempt successful done.

01:30:46

In programming, we have this concept called nested loops.

01:30:49

So we can put one loop inside of another loop.

01:30:52

And with this, we can get some interesting results.

01:30:55

Let me show you.

01:30:56

So I'm going to start with this loop for X in range five colon.

01:31:03

Now inside of this loop, I'm going to add another loop.

01:31:07

So for Y in range three colon.

01:31:13

And then in our second loop, I'm going to add a print statement.

01:31:17

Here we can use formatted strings to display coordinates.

01:31:22

Remember formatted strings, so we have F followed by quotes.

01:31:27

Now here we add parenthesis for our coordinates.

01:31:30

First, we want to display X and then comma followed by Y.

01:31:36

Let's run this program and see what happens.

01:31:39

There you go.

01:31:41

Pretty cool, isn't it?

01:31:42

So we get zero and zero, zero and one, zero and two.

01:31:46

Then we get one and zero, one and one, one and two and so on.

01:31:50

Now let me explain how exactly Python interpreter executes this code.

01:31:55

So here we have two loops.

01:31:57

This is what we call the outer loop and this is the inner loop.

01:32:02

So the execution of our program starts here.

01:32:05

In the first iteration of this loop, X is zero.

01:32:08

Now we get to this statement, which is a child of this four statement,

01:32:14

because it's indented four times.

01:32:16

This statement itself is a loop.

01:32:19

So what we have inside of this loop will be executed three times.

01:32:25

In the first iteration, X is zero because we are still in the first iteration of the outer loop.

01:32:31

And Y is also zero because we are in the first iteration of the inner loop.

01:32:36

That is why we get zero and zero.

01:32:39

Now we go to the second iteration of this inner loop.

01:32:43

In this iteration, Y will be one, whereas X is still zero.

01:32:47

That is why we get zero and one.

01:32:50

And similar in the third iteration of our inner loop will get zero and two in the terminal.

01:32:56

Now we are done with the execution of the inner loop.

01:32:59

So the control moves back to our outer loop.

01:33:02

Here we will be in the second iteration.

01:33:04

So X will be one.

01:33:06

And then we start here again.

01:33:09

So we have to execute this inner loop three times.

01:33:12

In the first iteration, Y will be zero, and X is one.

01:33:16

So here we have one and zero.

01:33:18

Then we will get one and one and one and two, you got the point.

01:33:22

So this is all about nested loops.

01:33:30

So you have learned how to use four loops to repeat one or more statements in your programs.

01:33:36

Now let's dive deeper and see what this range function returns.

01:33:40

So earlier you learn about the built-in type function.

01:33:45

With this function we can get the type of an object.

01:33:48

So if I pass five here and run this program, this is what we get.

01:33:54

So the type of this number or this object is int or integer.

01:33:59

Now let's look at the type of the value that we get from the range function.

01:34:04

So as an argument we pass, range of a number.

01:34:09

Let's run this program.

01:34:12

So this range function returns an object of type range.

01:34:17

So in Python we have primitive types like numbers, strings, and Boolean,

01:34:22

but we also have complex types.

01:34:25

Grange is an example of one of those complex types.

01:34:28

Throughout this course, we're going to learn about a lot of other complex types.

01:34:33

Now what is interesting about this range object is that it's iterable,

01:34:38

which means we can iterate over it or use it in a four loop.

01:34:43

That is why we can write code like this.

01:34:48

So this range function returns a range object which is iterable,

01:34:52

which means we can iterate over it.

01:34:55

In each iteration, X will have a different value.

01:34:59

Now range objects are not the only iterable objects in Python.

01:35:04

The strings are also iterable.

01:35:06

So here we can add a string like Python.

01:35:11

Now in each iteration, X will hold one character in this string.

01:35:16

Let me show you the print x.

01:35:19

And I'm going to delete these two lines here.

01:35:23

Let's run this program.

01:35:25

So in each iteration we'll get one character and print it.

01:35:30

We have another complex type called list, which we use to store a list of objects.

01:35:36

So we add square brackets, this indicates a list.

01:35:40

Now we can add a list of numbers or a list of strings, like a list of names.

01:35:45

You will learn about lists later in the course.

01:35:47

So let's run this one more time.

01:35:50

As we can see, we can iterate over lists.

01:35:53

In each iteration, we'll get one object in this list.

01:35:58

Now later in the course, I will show you how to create your own custom objects that are iterable.

01:36:04

For example, you will learn how to write code like this.

01:36:07

For item in shopping, cart, print, item.

01:36:13

So shopping cart is going to be a custom object that you will create.

01:36:17

It's not going to be an integer or string or Boolean.

01:36:20

It's a custom object.

01:36:22

It has a different structure.

01:36:24

You'll make it iterable so we can use it in a for loop and in each iteration, we can get one item in the shopping cart and print it on a terminal.

01:36:38

So you have learned that we use for loops to iterate over itrable objects.

01:36:43

In Python, we have another kind of loop that is a while loop.

01:36:47

And we use that to repeat something as long as a condition is true.

01:36:51

Here is an example.

01:36:52

So let's define a variable number and set it to a hundred.

01:36:57

Now we use while and here we add a condition.

01:37:01

As long as number is greater than zero, we add a colon.

01:37:06

Once again, we have a notation so we can repeat one or more statements.

01:37:11

We can print this number and then we can divide it by half.

01:37:16

So number equals number.

01:37:20

Use the integer division to divide it by two.

01:37:24

Or we can use the augmented assignment operator to shorten this code.

01:37:29

Like this.

01:37:32

Now let's run this program.

01:37:34

So here is what we get.

01:37:36

Initially our number is a hundred.

01:37:38

We divide it by half.

01:37:40

We get 50.

01:37:41

Then 25.

01:37:42

And so on.

01:37:43

So as you can see, in this example, we are not iterating over an iterable,

01:37:48

like a range object or a string or a list.

01:37:51

We are evaluating a condition and repeating a task.

01:37:56

Let me show you a real word example of a while loop.

01:37:59

In this interactive shell, Python is waiting for an input.

01:38:03

We can type something like 2 plus 2.

01:38:05

It will evaluate it and ask for the next input.

01:38:08

We can add another expression like 10 is greater than 2.

01:38:12

So these steps will continue until we press control D.

01:38:17

So behind the scene, we have a while loop that continues execution until we press control D.

01:38:24

That is the condition that causes the while loop to terminate.

01:38:28

Let me show you how to build something like this in Python.

01:38:32

So let's define a variable.

01:38:34

Command and set it to an empty string.

01:38:37

Now here we need a while loop.

01:38:40

We want this while loop to execute as long as command does not equal to quit.

01:38:46

So command does not equal to quit.

01:38:50

Column.

01:38:52

In this loop, we want to continuously get input from the user.

01:38:56

So we use the built-in input function.

01:38:59

We add a label like this.

01:39:02

Get the result and store it in the command variable.

01:39:07

This point Python interactive shell will evaluate this command.

01:39:10

We are not going to do that in this lecture because that's way too complex.

01:39:14

For simplicity, we can just echo back what the user entered.

01:39:18

So print, echo and as the second argument, we pass this command.

01:39:25

So this is our while loop.

01:39:27

It will execute until we type quit.

01:39:30

Now as I told you before, don't run this program using the code runner extension.

01:39:35

Because by default, it will run your program in the output window, which is read only.

01:39:40

So open up the terminal using control and backtake.

01:39:44

And run Python or Python 3 and that pie.

01:39:48

So here's our command prompt.

01:39:50

Let's type 2 plus 2.

01:39:52

It echoes back.

01:39:53

Let's type 3 times 2.

01:39:56

There you go.

01:39:57

If we type quit, our program terminates.

01:40:00

Now let's try it one more time.

01:40:02

What if we type quit and uppercase?

01:40:05

The program doesn't terminate.

01:40:07

Because as you learn before, lowercase and uppercase characters have different numeric representations.

01:40:13

So quit in lowercase is different from quit and uppercase.

01:40:18

Now to solve this problem, an amateur programmer may do something like this.

01:40:24

And command does not equal to capital quit.

01:40:30

So while command does not equal quit in lowercase and quit in uppercase,

01:40:36

continue getting input from the user.

01:40:39

Let's run this program in terminal and see what happens.

01:40:42

So one more time, Python after pie.

01:40:46

We type quit, beautiful, it works.

01:40:49

We type quit in uppercase that would work too.

01:40:52

But what if I type quit with an uppercase queue and lowercase UIT?

01:40:58

Our program doesn't terminate.

01:41:00

So this is a poor way of checking for the quit command.

01:41:04

What is the better way? Let me show you.

01:41:07

So we don't need this and operator here.

01:41:10

Instead, because command is a string, we can call the lower method.

01:41:16

So whatever the user types in, first will convert it to lowercase

01:41:21

and then compare it with quit in lowercase.

01:41:25

With this change, it doesn't matter how the user types the word quit.

01:41:29

We'll always terminate the program.

01:41:37

Now the last thing I want to discuss in this section is the concept of infinite loops.

01:41:41

An infinite loop is a loop that runs forever.

01:41:45

So if I change this condition to true,

01:41:49

because true is always true, this while loop will run forever.

01:41:54

So to jump out of this, we need a break statement.

01:41:57

So after we get the input from the user,

01:42:00

we can get the command, convert it to lowercase

01:42:04

and see if it equals to quit.

01:42:07

If that's the case, we want to break.

01:42:10

Now with this change, we no longer need to initialize command

01:42:14

to an empty string.

01:42:16

Previously, we needed this because we had a wild statement like this.

01:42:20

While command does not equal quit,

01:42:24

so we had to define this command variable,

01:42:27

and that's why we have set it to an empty string.

01:42:30

Without the line, when Python interpreter tries to execute this code,

01:42:34

it doesn't know what command is.

01:42:36

So now that we have an infinite loop,

01:42:39

we no longer need to define command and set it to an empty string.

01:42:43

So in terms of functionality, this program is exactly the same as the program we wrote in the last lecture.

01:42:49

Just be aware of this infinite loops,

01:42:52

because they run forever, you should always have a way to jump out of them,

01:42:57

otherwise your program will run forever.

01:43:00

And this can sometimes cause issues,

01:43:02

because if you're executing operations that consume memory,

01:43:05

at some point your program may run out of memory and crash.

01:43:14

All right, time for an exercise.

01:43:17

I want you to write a program to display the even numbers between 1 to 10.

01:43:22

So when you run this program, we should see 2, 4, 6 and 8.

01:43:26

And after these, I want you to print this message.

01:43:29

We have four even numbers.

01:43:32

Now here's a quick hint before you get started.

01:43:35

You should call the range function with 1 and 10.

01:43:38

Do not use the third argument, which is called step.

01:43:41

So basically, I want you to iterate over all the numbers between 1 to 10,

01:43:45

check if each number is an even number and then printed on the terminal.

01:43:50

So pause the video, spend 2 minutes on this exercise when you're done,

01:43:54

come back, continue watching.

01:44:00

So we started with a four loop for number in range 1 to 10,

01:44:05

colon.

01:44:07

We check to see if the remainder of division of this number by 2 equals 0.

01:44:13

So if number module is 2 equals 0, then,

01:44:18

reprint this number.

01:44:22

Now let's run this program.

01:44:25

So we get 2, 4, 6, 8, beautiful.

01:44:28

Now to count the even numbers, we need a separate variable.

01:44:32

So let's call that count.

01:44:34

Initially, we set it to 0.

01:44:36

Now in this if block, every time we find an even number,

01:44:40

we need to increment count.

01:44:42

So we set count plus equals 1.

01:44:45

And finally, after our four loop, we can print a formatted string.

01:44:51

We have count even numbers.

01:44:56

Let's run the program and here's the result.

01:45:00

So that brings us to the end of this section.

01:45:02

In the next section, you're going to learn how to create your own functions.

01:45:06

I hope you enjoyed this section and thank you for watching.

01:45:17

So far, you have learned how to use some of the built-in functions in Python,

01:45:21

such as print, round, and so on.

01:45:24

In this section, you're going to learn how to write your own functions.

01:45:28

Now you might ask, but why do we even need to write our own functions?

01:45:32

Well, when you build a real program, that program is going to consist

01:45:37

hundreds or thousands of lines of code.

01:45:40

You shouldn't write all that code in one file like we have done so far.

01:45:44

You should break that code into smaller, more maintainable,

01:45:47

and potentially more reusable chunks.

01:45:50

You refer to this chunks as functions.

01:45:53

So let me show you how to create your own custom functions.

01:45:57

We start with the Deaf keyword, which is short for define.

01:46:01

Next, we need to give our function a name.

01:46:04

So let's call this grid.

01:46:06

All the best practices you learn about naming your variables,

01:46:09

also apply to naming your functions.

01:46:11

So make sure your function names are meaningful, descriptive,

01:46:15

use lowercase letters to name your functions,

01:46:18

and an underscore to separate multiple words.

01:46:22

Now, after the name we need to add parentheses,

01:46:25

you will see why shortly, and then we'll add a colon.

01:46:29

Now, what is going to happen?

01:46:31

You know it.

01:46:32

We're going to get indentation, which means the following statements

01:46:36

will belong to this function.

01:46:38

So here, I'm going to add two statements.

01:46:41

Hi there, and welcome aboard.

01:46:46

Both designs belong to this function because they're indented.

01:46:51

Now, we are done with this function.

01:46:53

We need to call it.

01:46:54

So, we remove the indentation,

01:46:57

and we add two line breaks after this function.

01:47:00

This is what Pep8 recommends to keep our code clean and maintainable.

01:47:05

Now, if you forget to add two line breaks, don't worry.

01:47:07

As soon as you save the changes,

01:47:09

Auto Pep8 will automatically add these line breaks for you.

01:47:12

Let me show you.

01:47:13

So I'm going to remove these line breaks,

01:47:16

and call this function, create with parentheses.

01:47:19

Just like how we call the built-in functions.

01:47:22

Now, save the changes.

01:47:24

There you go.

01:47:26

So, we get two line breaks after our function.

01:47:29

Now, let's run this program.

01:47:31

So, we get these two messages on the terminal.

01:47:41

Now, here's a question for you.

01:47:43

What is the difference between the grid and print functions?

01:47:47

The difference is that this print function

01:47:50

takes an input, whereas our grid function doesn't take any inputs.

01:47:55

So, let me show you how to pass inputs like first name

01:47:58

and last name to this function.

01:48:00

When defining a function, in between parentheses

01:48:03

will list our parameters.

01:48:05

So, here we add two parameters like first,

01:48:09

on the line name, and last on the line name.

01:48:12

Now, with calling this function,

01:48:14

we need to supply two values for those parameters.

01:48:18

We refer to them as arguments.

01:48:21

So, mash, hamadani.

01:48:24

These are the arguments to the grid function.

01:48:27

That's one of the terms that a lot of developers

01:48:29

out there don't know.

01:48:30

They don't know the difference between parameters and arguments.

01:48:34

A parameter is the input that you define for your function,

01:48:37

whereas an argument is the actual value for a given parameter.

01:48:42

Now, let's change line two,

01:48:45

and instead of saying hi there,

01:48:47

we can greet a person by their full name.

01:48:49

So, we can convert this to a formatted string,

01:48:53

and pass two fields here.

01:48:55

First name as well as last name.

01:48:59

Save the changes, run the program,

01:49:02

and this is what we get in terminal.

01:49:04

Now, this function is more useful.

01:49:06

We can reuse it and call it with different arguments.

01:49:09

So, let's greet John Smith as well.

01:49:14

Run the program.

01:49:16

So, we get hi, mash, hamadani, and hi, John Smith.

01:49:20

Now, note that by default,

01:49:22

all the parameters that you define for a function are required.

01:49:26

So, here our grid function takes two parameters.

01:49:29

If I exclude one of these arguments and save the changes,

01:49:33

we can see we have this red underline.

01:49:36

So, pilot is complaining,

01:49:38

and saying there is no value for argument last name.

01:49:41

Also, if we run the program,

01:49:43

we get this type error,

01:49:45

greet missing one required positional argument.

01:49:49

So, let's put this back.

01:49:52

Now, later, I will show you how to define optional parameters.

01:50:01

So, this is the simplified version of this grid function

01:50:04

we created earlier.

01:50:06

Now, in programming, we have two types of functions.

01:50:10

Functions that perform a task

01:50:13

and functions that calculate and return a value.

01:50:17

Here are some examples.

01:50:19

Both the print and grid functions are examples of type 1.

01:50:24

The performing task, which is printing something on the terminal.

01:50:28

In contrast, the brown function is an example of a function

01:50:34

that calculates and returns a value.

01:50:37

So, the functions that you create fall into these two categories.

01:50:41

Now, let me show you how to rewrite this grid function,

01:50:44

but in the second form.

01:50:46

So, instead of printing this string on the terminal,

01:50:49

we simply return it.

01:50:51

Let me show you.

01:50:52

So, I'm going to delete all this code,

01:50:55

define a new function,

01:50:57

but call it get underlying greeting.

01:51:01

We add the name parameter,

01:51:03

simply return this form at a string high name.

01:51:08

Let's all we have to do.

01:51:10

So, we use the return statement to return a value from this function.

01:51:14

Now, we can call this function,

01:51:16

get underlying greeting, pass a name,

01:51:20

like mosh,

01:51:22

because it returns a value, we can store that value

01:51:25

and separate variable like message.

01:51:28

Now, you might be curious,

01:51:30

which form of this greeting function is better.

01:51:32

Well, with this first implementation,

01:51:35

we are locked to printing something in the terminal.

01:51:38

In the future, if you want to write that message in a file

01:51:41

or send it in an email,

01:51:43

we have to create another function.

01:51:45

So, we cannot reuse this grid function in other scenarios.

01:51:49

In contrast,

01:51:51

this second form is not tied to printing something on the terminal.

01:51:55

It simply returns a value.

01:51:57

Now, we get this value,

01:51:59

and we can do whatever we want with it.

01:52:01

We can print it on the terminal,

01:52:04

or we can use the built-in open function

01:52:08

to write this message to a file.

01:52:10

So, we can create a file like content.txt,

01:52:14

open it for writing.

01:52:16

This returns a file object,

01:52:18

and then we can call file.write message.

01:52:22

Now, don't worry about these two lines.

01:52:24

Later in the course, I'm going to talk about working with files.

01:52:27

But what I want you to take away here

01:52:29

is that we have this message variable,

01:52:31

and we can do whatever we want with it.

01:52:33

We can print it on the terminal, write it to a file,

01:52:36

send it in an email and so on.

01:52:38

And one more thing before we finish this lecture.

01:52:41

So, here's our grid function,

01:52:43

and as you can see, we're simply printing a string.

01:52:46

Now, if we call,

01:52:48

create, give it a name,

01:52:50

run the program,

01:52:52

we get this message,

01:52:53

hi-mosh.

01:52:54

But what if we put this inside of a call

01:52:57

to the print function?

01:52:59

Let's see what we get.

01:53:01

We get hi-mosh,

01:53:03

followed by none.

01:53:05

What is this?

01:53:06

None is the return value of the grid function.

01:53:09

So, in Python,

01:53:10

all functions by default,

01:53:12

return the non-value,

01:53:14

none is an object that represents

01:53:16

the absence of a value.

01:53:18

Later in the course, you're going to learn more about none.

01:53:20

What matters now is that all functions

01:53:23

return none by default,

01:53:25

unless you specifically return a value.

01:53:29

So, here, if we return some string,

01:53:33

none will no longer be returned.

01:53:36

Now, I just want to clarify something.

01:53:38

Earlier, I told you that we have two types

01:53:40

of functions in programming,

01:53:42

functions that carry out a task,

01:53:44

or functions that calculate and return a value.

01:53:47

So, back to the code we previously had,

01:53:50

so even though this function returns

01:53:52

non-by default,

01:53:54

it is still classified as a function

01:53:56

that carries out a task.

01:54:03

Let's create another function.

01:54:06

We call it increment.

01:54:08

We want to use this function

01:54:09

to increment a number by a given value.

01:54:13

So, here, we simply return number plus by.

01:54:19

Now, we can call this function like this,

01:54:22

increment two and one.

01:54:24

This returns a value, so we can store it

01:54:27

in a variable, like result,

01:54:29

and then print it on the terminal.

01:54:31

Let's run the program.

01:54:33

We get three.

01:54:34

Beautiful.

01:54:35

Now, we can simplify this code.

01:54:37

We have used this result variable

01:54:39

only in a single place.

01:54:41

That is line six.

01:54:43

So, we don't really need it.

01:54:44

So, on line six,

01:54:46

we can replace result with a call

01:54:49

to increment function.

01:54:51

Like this.

01:54:52

So, when Python interpreter executes this code,

01:54:56

first it will call the increment function,

01:54:59

it will get the result,

01:55:00

and temporary stored in a variable for us.

01:55:02

We don't see that variable.

01:55:04

And then it will pass that variable

01:55:06

as an argument to the print function.

01:55:09

Now, if we run this program,

01:55:11

we get the exact same result.

01:55:13

Beautiful.

01:55:15

Now, we can make this code more readable.

01:55:17

If someone else looks at line five,

01:55:19

they may not know exactly what these arguments are for.

01:55:24

We can use a keyword argument to make this code more readable.

01:55:28

So, this one here is the value of this by parameter.

01:55:33

We can prefix it with a name of the parameter like this.

01:55:38

Now, we can read this code almost like plain English.

01:55:43

So, if you're calling a function with multiple arguments,

01:55:47

and it's not quite clear what these arguments are for,

01:55:50

you can make your code more readable by using keyword arguments.

01:55:54

So, here, by equals one is a keyword argument.

01:56:03

Earlier, I told you that all the parameters that you define for a function

01:56:07

are required by default.

01:56:09

In this lecture, I'm going to show you

01:56:11

how to make the by parameter optional.

01:56:14

So, let's say we don't want to explicitly pass by equals one every time

01:56:20

we want to call this increment function.

01:56:23

We want to use this function to increment a value by one.

01:56:26

So, we remove the second argument.

01:56:29

Now, we need to give this parameter a default value.

01:56:33

So, we set it to one.

01:56:35

Now, if we call this function,

01:56:37

and don't supply the second argument,

01:56:39

this default value will be used.

01:56:41

Otherwise, the value that we specify here will be used.

01:56:44

Let me show you.

01:56:45

So, we run this program.

01:56:47

The result is three,

01:56:49

but if we pass the second argument here,

01:56:53

we'll increment two by five, so we will get seven.

01:56:57

So, you can see it's pretty easy to make a parameter optional.

01:57:01

Just be aware that all these optional parameters

01:57:04

should come after the required parameters.

01:57:09

In other words, I cannot add another required parameter here.

01:57:14

Let's call that another.

01:57:16

I cannot add that here.

01:57:17

If I save the changes,

01:57:19

you can see we get a red on the line here.

01:57:22

So, all the optional parameters should come after the required parameters.

01:57:28

Now, obviously, in this case,

01:57:30

we don't need the second parameter, so let's delete it.

01:57:39

There are times that you may want to create a function

01:57:41

that takes a variable number of arguments.

01:57:44

Here is an example.

01:57:45

Let's define this function, multiply.

01:57:48

That takes two parameters, X and Y,

01:57:51

and simply returns X times Y.

01:57:55

Now, we can call this function like this.

01:58:00

So far, it's so good.

01:58:02

But what if you want to pass one or two more arguments here?

01:58:06

That doesn't work, because our multiply function takes only two parameters.

01:58:11

To solve this problem, we need to replace these two parameters with a single parameter.

01:58:17

We use a plural name here to indicate that this is a collection of arguments.

01:58:22

And then we prefix it with an asterisk.

01:58:25

This is the magical part.

01:58:27

Let me show you what happens when you use an asterisk here.

01:58:30

So, temporarily, let's delete this line and simply print numbers.

01:58:35

Let's see what we get here.

01:58:37

So, run the program.

01:58:39

We can see all our arguments and their packed in parentheses.

01:58:44

What is this?

01:58:45

Well, earlier you learned about lists.

01:58:48

I briefly mentioned that you can use square brackets to create a list of objects,

01:58:53

like two or three, four or five.

01:58:55

Now, later in the course, we have a comprehensive section about lists.

01:58:59

So, don't worry about the details of lists and how they work.

01:59:02

But what I want you to note here is that the only difference between this list

01:59:07

and what we have here is in the notation.

01:59:10

So, use square brackets to create lists and parentheses to create totals.

01:59:16

Some people call it two poles or two poles.

01:59:19

So, a topal is similar to a list, and that it's a collection of objects.

01:59:23

The difference is that we cannot modify this collection.

01:59:26

We cannot add a new object to this topal.

01:59:30

Once again, later in the course, we're going to have a comprehensive section about lists,

01:59:35

topals, and other data structures.

01:59:37

What matters now is that these topals just like lists are iterable.

01:59:42

So, we can iterate over them, which means we can use them in loops.

01:59:47

Let me show you.

01:59:48

So, let's write for number in numbers, colon.

01:59:54

Let's just print one number at a time.

01:59:58

Actually, we don't need this line, so delete, and run the program.

02:00:03

So, we iterate over this topal, and in each iteration, we get one number and print it on the terminal.

02:00:09

So, now, with a simple change, we can calculate the product of all these numbers.

02:00:14

All we have to do is to define a variable like total.

02:00:19

Initially, we set it to one, and then in each iteration, we get total,

02:00:25

and multiply it by the current number.

02:00:28

Or we can rewrite this statement using an augmented assignment operator.

02:00:34

So, total times equal number.

02:00:37

Line 5 and 4 are exactly identical.

02:00:41

So, I'm going to use line 5 because it's shorter and cleaner, delete,

02:00:46

and finally, we'll return the total.

02:00:50

Now, one of the issues I see often in beginner's code is that they don't use this indentation properly.

02:00:57

So, they put the return statement here, and then they wonder why their function doesn't work properly.

02:01:03

If you put the return statement here, it will be part of the four loop, so it will be executed in each iteration.

02:01:10

In this case, after the first iteration, because of this return statement, we'll return from this multiply function.

02:01:17

So, the total will not be calculated properly.

02:01:20

We need to put this at the same level of indentation as other statements in this function.

02:01:27

So, here we have our four statement.

02:01:29

We loop over all the numbers, we calculate the total, and then finally return it.

02:01:35

So, with this implementation, we can get the result and printed on the terminal.

02:01:41

Let's run the program, and you can see the product of these numbers is,

02:01:46

120.

02:01:49

Hey guys, I just wanted to let you know that this tutorial is actually the first two hours of my complete Python master request.

02:01:56

If you're finding this helpful and want to dive even deeper, the full course covers everything from beginner basics to advanced concepts like machine learning, web development, and automation.

02:02:05

You'll also get hands-on projects to build your skills step by step.

02:02:09

I put the link in the description box if you're ready to take your Python knowledge to the next level.

00:00

Introduction to the Course

01:00

What Will You Learn

03:00

Why Learn Python?

05:00

Installing Python

08:00

Setting Up Your Code Editor

15:53

Using Linters in VS Code

19:35

Understanding Python Enhancement Proposals

20:20

Python Formatting Tools

22:56

Executing Python Code in VS Code

24:34

Python Implementations

32:32

Understanding Variables

32:40

Exploring Primitive Data Types

33:25

Understanding Boolean Values

35:15

Best Practices for Naming Variables

37:55

Mastering Strings in Python

49:11

String Methods Overview

49:15

Modifying Strings with Methods

49:29

Understanding String Immutability

54:00

Python Number Types

56:44

Using Built-in Functions with Numbers

01:05:51

Understanding Boolean Logic

01:06:47

Comparison Operators in Python

01:08:50

If Statements and Indentation

01:13:00

Using Else and Elif Statements

01:15:11

Using Logical Operators

01:22:39

Understanding If Statements

01:24:22

How to Use Loops

01:28:15

Implementing Break Statements

01:30:46

Introduction to Nested Loops

01:39:10

Using While Loops for User Input

01:40:10

Handling Quit Commands in Loops

01:41:37

Understanding Infinite Loops

01:45:24

Creating Custom Functions in Python

01:55:54

Making Parameters Optional in Functions

01:57:44

Understanding Variable-Length Arguments

01:58:59

Introduction to Tuples

02:00:14

Calculating Products with Iterables

01:13

What makes Python the fastest-growing programming language?

02:05

How does Python's syntax compare to C# and JavaScript?

02:36

Why is Python considered a must-learn for AI and machine learning careers?

13:44

What functionalities do you get by installing the Python extension in VS Code?

16:01

How does Pylint help improve code quality?

19:12

What are Python Enhancement Proposals (PEPs) and why are they useful?

20:54

How can autopep8 format your Python code automatically?

25:59

What are the different Python implementations and their purposes?

32:50

What are primitive data types in Python and why do they matter?

35:15

How do you effectively name variables for better code readability?

44:20

What are string escape sequences and how do you use them?

49:11

What are the key string methods to manipulate text in Python?

52:11

How do string methods like find and replace work in practice?

56:54

What built-in functions help handle numeric operations in Python?

01:06:54

How do comparison operators evaluate statements in Python?

01:09:49

What’s the importance of indentation in if statements?

01:14:15

How can you use if-else statements to simplify code?

01:23:09

What happens when comparing different data types in Python?

01:24:54

How can we use loops to avoid repetitive code tasks?

01:28:45

What’s the role of a break statement in a loop?

01:41:01

What’s the best way to handle case sensitivity in loop commands?

01:42:57

How can infinite loops cause memory issues in Python?

01:48:34

What’s the difference between parameters and arguments in functions?

01:56:29

How do you set default values for function parameters in Python?

01:59:16

What is the difference between lists and tuples in Python?

01:58:30

How can you modify a function to accept variable-length arguments?


DebuggingScripting languageDatabaseAPIAlgorithmArtificial intelligenceData analysisMachine learningPython (programming language)Web developmentObject-oriented programmingVersion controlProgram optimizationSoftware engineering

Description

The content begins with an overview of Python as a rapidly growing and popular programming language, appealing to a wide range of professionals, including software developers, mathematicians, and data analysts. It emphasizes a step-by-step approach to learning, ensuring that even those with no prior programming experience can follow along easily. Key topics include basic syntax, data types, control structures, functions, and libraries that are essential for practical applications. The material also touches on more advanced concepts, preparing learners for real-world scenarios in AI and machine learning. Additionally, it highlights the importance of building a strong foundation in programming principles, which will be beneficial for future learning. Throughout the content, practical examples and exercises are likely included to reinforce understanding and application of the concepts. Overall, this is a comprehensive introduction to Python that aims to equip beginners with the necessary skills to succeed in various programming endeavors.