Basics · 35:45
Python overview, variables and data types
Why Python for agents, variables and core data types.
- Python is the language of AI agents.
- Variables store values.
- Core types: int, float, str, bool, list, dict.
| Type | Example |
|---|---|
| int | 42 |
| str | "hello" |
| list | [1, 2] |
| dict | {"a": 1} |
Do this in your own tools, step by step. Ticks are saved on this device.
What stores values?
Variables.
Name two types.
str and dict.
0:00 You'll learn to write code and to architect systems that can reason, use tools, and solve real world problems using both proprietary and open-source AI. Hi, I'm Prashant Sahu, and [music] I'm excited to have you here as we take our first steps into the world of coding, data, [music] and artificial intelligence. In this course, we'll take a hands-on approach to learning. We'll start with the fundamentals in the module one where we will dive into Python basics, variables, data types, functions [music] and more.
0:49 By the end of this module, you'll be writing clean, efficient Python code and we'll have a solid foundation for tackling complex tasks. Next in the module two, we'll work with files [music] and databases. We'll explore pandas, one of the Python's most popular libraries for data analysis, and [music] get hands-on with databases and SQL. You'll learn how to connect Python to databases and manage [music] data effectively, a crucial skill for any aspiring AI practitioner. In a module three, we'll explore APIs, what they are, why are they essential, and how to use them in Python.
1:36 You learn to connect with external services, work with JSON data, [music] and handle common challenges like authentication and rate limits. We will introduce you to how APIs power [music] AI agents and large language models, which is where things get really exciting. Finally, in the module 4, we'll dive into working with language models, often called as LLMs. You will learn how to use libraries like OpenAI and explore open-source tools like hugging face. We'll cover how to access prompt and interact with LLMs, giving you a peak into building intelligent systems.
2:23 Overall, by the end of this course, you will not only understand Python programming, but also have hands-on experience working with data, connecting with APIs, and interacting with cuttingedge language models. I'm here to guide you at every step of the way, and I can't wait to see what you will create. Also, in case you want to dive deep into generative AI, machine learning, and deep learning, feel free to check out some free courses made by my team.
2:47 Before we dive into the details of Python and its relevance in data science, I would like to give you a quick overview of what Python is and why it has become so crucial for today's data professionals. Python as you may know was created by Gaidoan Rasum in 1991. Since then it has been developed and maintained by Python software foundation growing into one of the most widely used programming languages globally. Now let's talk about the background of Python.
3:11 Python is known as a highlevel generalpurpose programming language. Python has become incredibly popular because of its readability and flexibility. It is used in various fields such as scientific computing, web development and artificial intelligence amongst many others. One of its biggest advantages is that it is an interpreted language means it runs in a virtual environment which makes it platform independent. This means that it can run on almost any system like Windows, Mac OS or Linux without much hassles.
3:59 Now, why should we use Python for data science? The short answer is that it ticks all the boxes. First, Python boasts a large and active community. This is really helpful because you have access to countless tutorials, forums, and even solutions to problems you might face, making the learning curve much smoother. Secondly, Python syntax is very easy to understand which allows data scientists to focus on solving complex problems rather than spending too much time on intricacies of coding.
4:25 It is also open source which means it is free to use and there's a continuous stream of improvements for developers from all over the world. Another big advantage is Python's rich collection of libraries like pandas, numpy, mattplot lib and scikitlearn. These libraries make tasks like data manipulation, visualization and machine learning easier and more efficient. The widespread use of Python in data science also translates into plenty of job opportunities which is another huge plus. Before we start coding, it's important to set up your system properly.
5:10 For data science, many developers prefer working in an integrated environment like Jupyter Lab or Jupyter Notebook. Jupyter Lab allows you to write, execute, and document Python code all in one place, making it perfect for data analysis and visualization. We'll walk through the steps of installing and setting up Jupyter Lab which will ensure you have the right environment for working with Python throughout this course. Now let's go to Google and search for Anaconda. We'll click on the first link and this is the web page from where you can start downloading Anaconda distribution for Python.
5:56 On this page you can find the link to download the Anaconda distribution. So if you see here below the submit button, there is a skip registration uh link. Let's skip the registration and straight away go to the download page. So this is the download page. Based on your operating system, you can click on the links to download the installer files. So here I'm using a Windows system. I'll click on the 64-bit installer which is 912 mgabytes.
6:19 So it might take some time for you to download. So let's wait. So once we have uh downloaded the Anaconda installation file, double click to start the installation. Okay. So I have double clicked on the installer file and this is the installation wizard which will appear. So let's click on next. Agree to the license agreement and then it shows you a screen whether to select the installation just for you or all the users. go with the just me option which is the recommended and then it will uh select a default path based on the operating system for installation.
7:07 Make sure you have enough space in your C drive. So by default the installation directory is C users username and then uh Anaconda 3 and uh there are some options uh given to you whether you want to add Anaconda or Python in your system path. Go with the default options and just hit install. It will take some time for you to install this uh around 2 to 3 minutes. So based on your systems configuration. So let's wait.
7:30 Once it is installed, we'll come back. Now once the installation is complete, this is the window that will appear. Just click next and next and finish. So it will give you an option to launch the Anaconda Navigator, which we will uh leave checked and uncheck this last option. Okay, the Anaconda Navigator has been launched. This is how the window looks. I'll just click on uh don't show this again. So, let us see what all packages have been installed within Anaconda Navigator.
7:54 So whichever says launch all these softwares have been installed when you install Anaconda Navigator which means PyCharm is not installed. If you see Anaconda toolbox is installed, notebooks are installed, Jupiter lab is already installed. Okay, Jupyter notebook is installed and we'll be using Jupyter Lab and Jupiter notebooks extensively in this course. So let's click on the Jupiter lab launch again. It will take a couple of minutes for this to launch. Remember that the Jupiter lab will launch in the browser window.
8:44 So I've got my Jupiter lab up and running in the browser window. There is one small warning. Do not close the Anaconda Navigator window as long as you are running the Jupiter lab from here. Okay. So the default installation directory is shown on the left side. This is the file browser window you can see and from here you can actually launch Jupiter notebook. You can have access to the Python console or a terminal. You can also create u uh requirement.txt file from here and you can also create markdown f files with an extension md.
9:31 You can create standard python files with an extension py and you can also access the other applications from anaconda. Okay. So uh first we will learn how to create a folder within Jupyter lab and then we'll learn how to create a new file a new Jupyter notebook from Anaconda environment and see okay so first you need to decide where you want to keep your code files let's say I want to keep my code files within this is your C and users directory okay from here uh I am just browsing to desktop so just Right click and create a new folder from here.
9:56 Okay. Specify a folder name. So my folder name is coding essentials for AI. Double click on that. So the folder appears to be empty as of now. And again if you want to create a subfolder you can go ahead and do that. Let's say I create module one. And within module one double click. So to create a new Jupyter notebook, right click and click on the new notebook option. This is the window that will appear. This will ask you to select the Python kernel to associate with the notebook.
10:45 So you can see that I have no other kernel apart from this basic Python 3. So I'll go ahead and take that. Uh you can also check this to start with Python 3 as your preferred or the default kernel. So kernel is the program which interprets your Python code and executes it. You can resize these windows. So this is how your uh coding window looks like. This is my coding window. And on the left side I have again my file browser window.
11:07 Here you can type your Python codes. My first Python program let's say print hello world. And to execute this you can do a shift enter or control enter. You can also click on this button to execute this cell. Okay. So codes are written in code cells. This is one code cell whichever is highlighted in blue uh boundary. So that's a code cell. You can see that this is currently in the code mode. So you can also change the mode of the cell.
11:31 So this is currently in the code. So I'll click on this. This will execute the cell. So once the cell is executed, the output of the cell is displayed just below the cell. So this is one way you can execute the cell. Otherwise, if you want to do it from your keyboard, you can do a shift enter or control enter. Shift enter will execute the current cell and advance to the next cell. Control enter will execute the current cell and stay there.
11:55 Now let's have a look into another coding environment which does not require any installation and can be accessed from anywhere in the world and that is Google's collab. So that also opens in another browser window. But you need to first sign in into your Google account. So we'll go to Google and uh search for Google Collab and here in the first link click on that. So assuming that you are already signed into your Google account this is the window that should appear.
12:40 If you have already previously opened any Google Collab notebooks that will also be displayed. So on the left side you can see there is a menu table of contents some standard uh collab notebooks would be there. So what I'll do is click on file new notebook in drive. This will create a new Jupiter notebook and that will be saved in your Google drive. Okay. So on the top you can double click and provide a name to your Jupyter notebook.
13:06 Your Jupyter notebook will have the extension IP NB that is interactive Python notebook as the default extension. And again as usual this is your code block. Okay, you can type your Python code. So let's say this is my first hello world program in Python. And again you have three options to execute. But before that on the top right make sure that you have connected your Jupyter notebook with a remote Python kernel which will be running on Google's server.
13:55 Okay. So you have many options but we'll go with the default option right now. Click on the connect to a new runtime. So make sure that your Jupiter notebook is connected to a runtime. Once it is connected, it will show a tick mark. This might take 15 to 20 seconds for it to connect. Uh please note that in the free account of Google Collab, you cannot run parallelly more than one collab notebooks. If you try to run another collab notebook, it will ask you to shut down the previous notebook.
14:21 So this is one limitation with the free account for Google Collab. So as you can see uh there is a green tick which means my collab notebook has already been connected to the remote runtime. So now I can go back to my code and again I can execute this. So again execution has three options. You can click on this icon to execute the cell or you can do a control enter or a shift enter. So I'll click on this link and uh you can see the output of this cell is below the cell.
15:06 Okay. So this is how you can quickly create your codes in uh collab notebook environment. And if you're curious to know where is this notebook saved, you can go to file and locate in drive. So this will go to the exact collab notebooks folder in your Google account. So now as you can see all my collab notebooks are located in the my drive collab notebooks folder. Okay. So this is the module one Jupyter notebook which I created on uh collab and there are some other notebooks which I had already created.
15:31 So this is present within my drive collab notebooks. So this is how you can actually also upload your collab notebooks to this particular drive and execute it from there. So let's say if you want to execute it from here, you can open any of the existing notebooks by right-clicking on it and open with Google Collab. This is how you can open any Jupyter notebook. Once you have uploaded it on Google Collab, right click and open it on Google Collab.
15:54 So this will open it in another tab from where you can again connect to a runtime and start executing. So that's it for this particular video. See you in the next one. Thank you. Hello and welcome back. In this video, we'll dive into some foundational concepts that are essential for coding in Python. The variables, data types, and operators. By the end of this session, you will understand how to declare variables, use different types of data, and perform operations on them.
16:43 So, let's get started. Let's get started with the variables and data types. First, let's talk about variables and data types in Python. Think of variables as a container that stores information like a number, a word, or even a list of items. Python makes working with variables very easy. You don't need to declare them explicitly unlike some other programming languages. Just give them a name and assign them a value and voila, you are ready to use them.
17:06 For instance, here we see different data types like numbers, strings, and even more complex data types like lists and tupils. Each of these represent a different type of information that Python can handle. Now, let's understand how to declare and assign values to variables. In Python, you can declare a variable simply by assigning a value to it with a equal to operator. Let's say we want to store the number 50 in a variable named a. We just write a equal to 50.
17:29 That's it. No need for any extra keywords or statements. Python is very intuitive in this way. If you want to store a in another variable, we can do something like B equal to A. This assigns the value of A to B, making both variables contain 50. Simple and effective. Python has a few core data types that you will be using often. These include integer for whole numbers, float for numbers with decimals, string for text, boolean which represents true or false, and none which represents a variable that has no value.
18:17 We also have some collections like list, tpples, dictionaries, and sets which are often very helpful for grouping related data. Here you can see strings as well because strings are considered to be collection of characters in Python. Understanding these data types will give you a powerful toolbox for tackling almost any coding problem. There are a few simple rules when it comes to naming variables in Python. First, variable names are case sensitive. So small ABC and capital ABC are considered different variables.
19:06 Also, variable names must start with a letter or a underscore and never with a number. You can also use numbers in the name, but they can't be at the beginning. And avoid using Python's reserved keywords like if, else, for, while, def, return. These have special meanings in the Python language. As an example, a good variable name might be student score. While something like 123 score is not allowed. Keeping these rules in mind will help avoid any errors as you code.
19:30 Now it's your turn. Let's practice what we have learned by declaring and assigning some variables in Jupiter notebook. So let us first start the Jupyter notebook. I will search for Jupyter notebook. So run this Jupyter notebook app. Uh once it is started, it will open in a new browser window whichever is your default browser. So you'll have access to all these folders. This is typically present within your C uh users. So these are all the folders which are present within the C users directory.
20:16 You can browse all your files from desktop, documents, downloads and so on. Now only problem is my code files which I have downloaded for this particular uh module are in the D drive AI agent and code files. So first we will have to actually browse and change the directory to this one. Okay. So for this we'll close this and start with Anaconda prompt. Make sure you are selecting the Anaconda prompt. Now this is different from your normal command prompt.
20:40 How your Anaconda prompt will have this base written. normal command prompt will not have that base. Okay, close this. Now since my folders are in D drive, I'll directly go to D drive first and from there I can actually start my Jupiter notebook. If you do not do this, you will not be able to access D drive files. You will only be able to access the files which are present within C users and whatever the username.
21:04 Press enter. And uh this might take some seconds to open. Okay. So interface is still the same. It's just that the technique that I've used is slightly different so that I get access to the actual code files which I have saved in my desired directory. So you can see uh these are the folders present within the D drive. So this is where my AI agent code files are. Okay. So now you can see all the Jupyter notebooks for this particular module.
21:52 I'll double click on the first one which is implementing variables and data types in Python. So let's get started. Okay. So you can execute all the codes uh by using or by clicking on this button which is the run button. Okay. or a keyboard shortcut you can use that is shift enter or control enter. So I'll use this keyboard shortcut key uh shift enter. So let me define a variable name a and assign a value equal to five.
22:17 So how do I know that the value has been assigned? Let's print the value of the variable. So when I executed this cell by using shift enter this is the value of five that I have got for this a. So this way you can define any variable name and using the equality operator you can assign a value to it. Okay. You can also use the print function to print the value of the variable. You can see that print a gives me five.
23:05 Fine. So here I am defining a equal to 7 and I am creating another variable b and assigning the value back to a and then changing the value of a from 7 to 3. Let's see what happens. So what will be the value of a now? Since the value of a has been changed from a equal to 7 to a= 3, this should give me a equal to 3. Perfect. And since B was assigned a value equal to A when A was having a value of seven, B should still point to the original value of A which is seven.
23:30 Super. [snorts] So this is how the variables work in Python. Now we have already discussed the variable name rules in the presentation. So here is a quick recap of those rules. Python variable names are case sensitive which means small A and capital A would be different. Um identifiers or variable names can be a combination of letters, lower case or upper case and digits. You can even use underscore. You can use the underscore at the start or at the end.
23:56 So these are all valid variable names. You cannot use a variable name which starts with a digit. So for example, one variable is not valid but variable one is perfectly fine. So let's see and then finally you cannot also use keywords as variable names because keywords are reserved. So if you try to assign any value to any of these keywords, Python will throw you an error. So here I've defined uh let's say a equal to 400 and small a as 400 and capital a as four.
24:43 Let's see what happens. So you can see that small a still points to 400 and capital a points to four. So some of the rules let's verify them quickly. So underscore a is valid. Okay. But if you say a underscore that is also valid. Okay. Because underscores are acceptable. But if you have any other special characters either at the start or at the end that will be invalid. Okay, you can see that's an error message saying the syntax error.
25:09 Same syntax error you will get when you try to define 1 a as five. If you try to assign a1 as five or 500 whatever that number is that is perfectly fine. So now we'll move on to the section of uh data types. Let's create some of the variables from different data types. Here I'm creating a as a integer. We can check the data type by using the type function. Type is a built-in Python function which is used to check the data type of any Python object.
25:33 So you can see that uh the data type assigned to A is a integer. Similarly, let me create a string data type. So B is uh luxe. So you can very well see that uh the strings are created by using double quotes. You can also create string by using single quotes. So the data type of B is a string. For floats you can uh assign the value directly. Just make sure you have a decimal point. So here the value assigned to C is 5.55 and you can see the data type is float and boolean you can create either true or false.
26:21 Okay. So you can see the data type let's say E s false. So D and E both are boolean. And if you are interested to see what all variables are present in your current name space just type whose and you can see that all these variables are existing in the current name space. Okay you can use all these variables for calculations. So let's do some quick data type conversions. Let me convert a float into integer. So my age is 26.3333 something.
26:49 I am converting that age into an integer by using the int function. int is used for type casting uh float to a integer. Okay. So you can see 26.333 has been type casted into integer. So what this function does is it simply ignores the decimal point and anything beyond the decimal point. It only takes the integer part of that float. Similarly, I can convert a string into integer also. So if I'm trying to add a string to a uh integer, this will give me an error.
27:38 So this is a string in single quotes and this is an integer. So you cannot add a string to integer. This operation will give me a error. You can see. But if I type cast this two from string to an integer this I'm converting this two from string two to a integer two I can still add with this integer six okay so let's do that perfect so this is how it works okay here the two string two was type casted into a integer and then this becomes integer this is already integer so integer addition happens and finally returned is also an integer you can check that the data type of my int is also an integer.
28:26 I'll see you back in the presentation and we'll continue with the operators in Python. In Python, operators are symbols that perform operations on variables and values. These include arithmetic operations like addition, multiplication, division, and more. Think of operators as tools in a toolbox. They help you manipulate the data stored in your variables. For example, if you want to add two numbers, you would use the plus operator. Easy, right? And operand is the value on which the operator is applied.
28:50 Python provides several types of operators. The arithmetic operators for basic math. Comparison operators to compare values like greater than or equal to. Logical operators for combining multiple conditions. Bitwise operators for working with bits. Assignment operators for assigning values. Identity operators to check if two variables refer to the same object. These operators allow us to perform complex calculations and make our code much more powerful. For example, you could use a comparison operator to check if a student score is greater than 50 and then use a logical operator to decide what to do next.
29:38 It's time to practice using operators. Let's open our Python editor and try out some arithmetic and comparison operations. So, we have already learned the concept of variables and data types. Now, we'll proceed to operators in Python. I'll double click this file and open it. So as we have already seen there are uh different types of operators in Python. Arithmetic operators for mathematical computations, comparison operators, logical operators, bitwise operators and so on. Let's experiment with some of these operators.
30:00 So here I'm creating four variables. A with a value of 15 which is an integer. B with a value of 8 again an integer. C with a value of 15.5. Uh C will be a float. And S is hello with single quotes. It's a string. So let me execute this. Okay. So these are the most common arithmetic operators available in Python. Plus is used for addition, minus for subtraction. This is asterisk uh used for multiplication of two numbers.
30:47 This is for division of two numbers. This is the modulo operator. Uh this will give you the remainder after division. Uh for exponentiation you can use two asterics. Okay. [snorts] And this is for flow division. Flow division typically gives you the quotient part after division. So let's see addition of a and b. I'm subtracting a from b. So let's see some of these operators in action. So I'm adding a and b. Uh now I'm subtracting b from a.
31:13 So I'm dividing a by b. So a is we have seen is 15 b is 8. So this is 15 divided by 8. This is 15 * 8 120. And uh this is exponentiation. So 2 to 2 to the^ of 3. Similarly you can just change this number. 2 ^ of 10 would be 1024. So this is for exponential or powers. So this is flow division. So this is 15 divided by 8. Um and you are only looking for the quotient part which is one and modulo operator will give you the remainder.
31:42 So remainder should be seven. So when 15 is divided by 8 you'll get one as the quotient and seven as the remainder. Let's have a look into some of the comparison operators. So 2 * equality sign will be used to check the equality between two operants. This is for not equal to for greater than. This is for less than, less than equal to and greater than equal to. So I'm checking whether let's print the value of a and b before we go ahead.
32:29 So a is 15 and b is 8. I'm checking whether a is equal to b. It says false. Certainly a is not equal to b because a is 15 and b is 8. Now I'm checking whether a is equal to 51 or not. So a is not equal to 51 because a is actually equal to 15. So here I am checking whether a is equal to b or not and checking the data type of the returned output.
32:55 Here the output will be a boolean you can see. So for all these comparison operators the returned output will be boolean type. You can see true false true false. So that true false is basically a boolean data type. Now I'm checking whether a is greater than b. Yes indeed it is greater than b. A is less than B. This should return false. A is greater than 51. No, 15 is less than 51. So it is false again.
33:20 Now for logical operators, uh and or and not. So is 1 equal to 1? This will return me true. Is 2 equal to two? Yes, this will also return me true. So if this is true and this is true, the net thing will give me true. So true and true will give me true. This is true. This is false. So true or false will give me again true. That is how the truth table for the or operator works.
33:44 So and operator will give you true only when both of them are true. If either of them are false. Okay, let me make it clear. So let's make it 20 here. So this is true but this is false. Right? So this will give me false. So and operator will return true only if both of these conditions are actually returned to be true. Okay. Simultaneously if either or both of them are false then the net returned output would be false.
34:31 You can see here. Okay. So this will go back to true. But in the case of R operation there are two conditions again which I'm checking. So if either of them are true, it will give me true. So this is true. This is false and still it gives me true. Okay. But if both are false, let's say this is 10 now. Okay. So one is not equal to 10. So this is false. Three is not equal to four.
34:53 This is also false. So false or false will return me false. If either of them is true, then it will give me true. You can see that. Okay. Now you can go for more compound operations. Okay. So you can uh focus on the bracket here. So first I'm checking this condition within this bracket and then I am compounding it with the or operation with this condition. Okay. So first we check whether two is greater than three.
35:20 This will give me false. This will give me true. So false or true will give me true. So the output from here to here will be true. Now this is true and this is already true. So the net thing should return to be true. That's it for this
Get the other 14 chapters, the exam and your certificate for LinkedIn, plus all 700+ AI courses.