Python Crash Course #2 - Python Basics

Net Ninja · Beginner ·🛠️ AI Tools & Apps ·2y ago

Key Takeaways

This video series covers Python basics, including data types, variables, and basic operations, using tools like Visual Studio Code and Python.

Full Transcript

hello there and welcome to the first part in this python Series where we are going to write actual python code at the moment you should have python installed and you should have access to a code editor I will be using visual studio code but any code editor is fine choose whatever you like what we are going to learn in this video is how code is executed we are going to cover math operations and displaying text and finally we're going to get basic user input this is the screen that we finished on in the last video where we have printed the word test meaning if you're running the code again we are getting the word test that's a pretty good start but not what I want to do for this video instead I want to create a new python file this I Do by going to the Explorer on the left side if you can't see it it's this symbol just click on it and then right click on this area and create a new file this now needs a name and I want to call it basics dopy really important you need thep ending only because of that does visual studio code know that we are working with a python file if you now press enter we have a new python file on top of that if you open the folder where we are working in besides setup we now also have basics. piy this is the file we just created with that I can go into full screen so we have fewer distractions now just to test that this file is working let me print let's say line one if I run the code again which I can do either by going on this triangle or in my case I can use the custom hotkey alt and a that is doing the same thing I set this one up in the last video if we are doing that we are getting the output line one and all of this is getting a bit messy if you want to clean it up you can go to these three dots and then clear terminal that way things are a bit cleaner and if you run it again you get a bit less clutter it's still not ideal but it's good enough the thing we care about is line one so we know this python code is working cool that's a good sign which is bringing us to the First Fundamental concept code in Python and basically any programming language is always executed from the top meaning line one and then we are going down for example if we have more than one line we have line one line two and line three we always start with line one then we execute the second print statement and then we execute the third print statement which means if I run the code now we can see line one line two and line three in this order later on we are going to learn how to manipulate this order for example to create a loop where code runs forever or the ability to only run code if a certain condition is true but for now we always run code from the start to the end like you would read any book I think that makes sense also what you can do to organize your code a bit better is to add comments which you do with the hashtag symbol anything after that will be ignored by python let's call this one the execution order you can also write a comment after a line of code all you have to do is set the hashtag and anything after that will be ignored so this will be ignored super handy to add some annotations to certain lines of code or to entire blocks cool with that we have the first important concept the next important concept would be data types because in Python we have multiple the one we have already seen let me print it again is simply words so let's call it words this could either be done with single quotation marks or with double quotation marks meaning if I print double quotation mark words we would get the same result if I run the code again we get words two times one with single quotation marks and one with double quotation marks python doesn't really care you just have to be consistent besides that the other data type would be numbers for example we could print 1 2 3 we could print -10 or we could print 1.5 I can run all of this again and we're getting words and then the numbers that we have just specified these values are created via different data types words in Python are called strings and those you create either with single or with double quotation marks both would be fine numbers can be integers or ins in short and those could be either positive or negative and if a number has a decimal point it is called a floating point value or simply a float internally python is processing these numbers slightly differently compared to the integers but that's not something you have to worry about what you do have have to worry about however a basic let's call it operations for example what you could be doing is print let's say 3 + 3 also what you can do with comments is you can select all of this and then press control and to forward slash that way you comment out all of the selected lines of code if you press the same comination again you un comment them in our case we're going to print 3 + 3 if I now run the codeing again we're getting six and once again let me clear the terminal so we can focus on what's Happening Here we are just getting six the result of 3 + three that should make sense there are multiple math operations you can work within python in my case I want to duplicate this line which you can do with alt shift and then the down arrow that by you duplicate the line downwards the basic meth operations are plus minus multiply and divide if I now run all of this we get 6 0 9 and 1.0 the respective results of these four operations notice here that whenever you are divide a value in Python the result will be a floating point value which is interesting but not something you have to be concerned about because you can add these values up totally fine for example we could do 10 plus 0 some longer floating point value if I know them together we get the expected result so integers and floating Point values can be added together perfectly fine what cannot be added together would be integers or floating Point values and strings and this should make sense imagine somebody asked you to add together 10 and the word hello you wouldn't have any idea what to do with that and python is in the same spot if I try to run the code we getting an error message that we have a type error unsupported oper and type for Plus in and string python just doesn't know what to do with this operation and for good reason it doesn't make any sense what you could be doing however is 10 multiplied with hello and the result of that is going to be the string hello 10 times this isn't something you usually do but in very rare circumstances this can be useful what I want you guys to focus on is that sometimes you can add different data types together very easily like integers and floating Point values but other times this is not possible for example multiplying an integer with a string is a bit weird but doable but you can't add them together there aren't really that many rules most of the time the expected result is what you would be getting speaking of which there's one more thing I want to cover and that is the order of operation let's say we have an operation like 13 - 3 * 4 + 2 what do you think think the result is going to be from all of this well let's run the code and the result is going to be three the correct order of operation is that you always start with multiplication meaning 3 * 4 would be 12 after that we can do 13 - 12 + 2 and that's quite easy this would simply be three the result we have gotten down there but sometimes you do want to be a bit more specific for example you might want this 4 + 2 to be prioritized for that you can use parentheses and put them in there if I now run this again we getting minus5 we are getting this because we start with the parenthesis operation this would be 4 + 2 or 6 which we are multiplying with three this would give us 18 and then the final calculation would be 13 minus 18 which is -5 exactly what we have gotten down there that should be reasonably straightforward so next up we can cover variables and what variables allow you to do is to work over multiple lines at the moment we are always constrained to a single line of code we can do this one this one or this one but we couldn't connect this line to this line or this line to this line for that we always need a variable and a variable is just a bucket where you can put a value into and take a value out or change the value and do stuff like that let's say I want to create a variable called test which you do by simply writing test and then to assign it a value you will need the equal sign for example in this case I want to give it the value one 2 and three we have created a variable with the value 123 this we can then use for example we could print it and if I run all of this again we are getting 1 two and three to python this test is simply the value of 120 and3 which means you could even use this in math operations let's say + 10 run all of this again and we're getting 133 123 + 10 with that setup you can connect multiple lines for example what you could be doing is test is the same value except we are adding 50 to it and then we simply want to print the output run all of this again and we're getting 173 on line 23 we're creating a test variable with the value 123 on the next line we got the same variable and assigned it a new value with this equal operator after that we got the value of the variable itself and then added 50 the result was 173 now this line isn't particularly elegant and python has a shortcut for that what we can do is plus equal 50 that why we taking the same variable and adding a value to it so if I now run out of this again we are still getting 173 variables are incredibly useful and we are going to use them all the time although when using them you do have to be careful because there are some limitations on the name you can use let's talk about that when it comes to variable names there are some parts that are mandatory if you're not doing them you are going to get an error message most importantly you can only use the letters from A to Z both lowercase and uppercase the numbers 0 to 9 and the underscore symbol these are the only characters that are allowed besides that we cannot start with a number meaning one test would be invalid but test one would be fine after that variable names are case sensitive so test 1 to three would be different from test 1 to3 because the first one has a lowercase T while the second one has an uppercase t as far as python is concerned those are two entirely separate variables finally the last limitation is that we cannot use the names of inbuilt functions so for example print couldn't be a variable name that would be really confusing after that there are a couple of things that are beneficial but not mandatory the first one is that you should be clear with your variable names for example you could create a value that is called a and assign it a value of let's say 150 this a has no inherent meaning if somebody else was to look at it they would have no idea what you are trying to do also when you are not looking at this code for half a year and come back to it you will yourself have no idea what this a stands for so you shouldn't use this kind of a at all it should be something more descriptive depends on your use case but you should rather have longer than shorter variable names after that you should also use what is called snake case what this one means is that every character is always lowercase and if you want to separate two words as one variable name you are separating them with an underscore back in the code this test we could call for example test value and since this name changed we have to change the name of all of the other test variables as well so we stay consistent if I now run this again we get the same outcome so test value is perfectly fine still not an amazing name for a variable but it will do for now what you couldn't be doing however is add a number at the beginning that way you immediately get a scary red color so you can see this one isn't working you also wouldn't be allowed to use other characters like for example a pound sign there you can see we got an error message right away also what is not allowed to have a space between these values there you can see right away we get lots of error messages so let's not do that creating variable names will eventually become quite straight forward and you develop an intuition for it for now don't worry too much about it as long as you don't get an error message the variable name is going to be fine which means now we can come to the last part of this video and that is getting input and for all of that I want to comment out the earlier parts so we can focus on one thing at a time to get input you will need a function that works kind of like the print statement it is called input this one like print wants to have a string that it is going to display for example we could write please write something if I now run the code and let me clear the terminal once again there we get please write something with a Square afterwards and there we can actually type something so e word and if I now press enter we are finishing the code so what happened well when you are running this this kind of command python is going to display the text and then check for user input which in our case is working totally fine the issue is we are not storing the value or do anything with it for that though we can use a variable for example we could assign this value to a variable called user input and then on the next line we could print that user input also what I want to do is to add a space after some thing still inside of the quotation marks what that is going to do if I run the code again we are still getting the same please write something but now after that and the input Square we're getting one line of a separation this is the space we have just created looks a bit cleaner but isn't too important what is much more important is that now we can write any kind of value let's say test if I now press enter we are printing test right afterward words so basically what happened is that this input got the value of test and this value was stored in the user input variable and on the next line we are printing that value which is what we have gotten down there with that we can get some user input and later on we will learn how to manipulate this value which is basically all that programming really is cool with that we can do an exercise and then we are done with this basic part what I want you guys to do is to create a greeter app this will consist of two major parts number one I want you guys to write the logic to ask the user for the name and then print something like hello username and have a nice day or some kind of greeting now for that you will have to figure out how to print multiple values on one line with a single print statement at the moment you do not know how to do that for that you will have to do some research look online either in Google or in chat GPT to figure out how you can add multiple values into a print statement should be fairly straightforward and throughout the series I will make you do research quite often it is a really important skill as a programmer that you have to learn early on but anyway pause the video now and see how far you get righty back inside of the code I want to comment out the user input bit we just did and instead add a comment for the exercise first of all we have to write an input state where we are asking the user for the name let's say what is your name with a question mark and a space afterwards so we have a bit more spacing if I run all of this now we get what is your name and we could write Bob although after that nothing is going to happen simply because after this input we're not doing anything with the return value we could store this inside of a variable let's call it user uncore name and and assigned the value after that we can print the username and now if I run all of this again we get what is your name again let's write Bob and we are getting Bob so that is progress but what I want to do is to write hello user name and then some kind of greeting like have a good day how can we do that and for that we will need to do some research what you would be looking for for example would be python print multiple values or something like that the first result is stack Overflow which is a website where you can ask questions and usually get really good answers but in our case we don't really need that although if you read the first line you can just pass in values as parameters so print value comma another value and then another value that's basically the answer but in our case I want to scroll down a bit and there for example we get websites like tutorials point or Geeks for geks those are really good and very common let's have a look at tutorials point in there we're getting a couple of explanations of the basic function and if you look a bit further down all we have to do to print multiple values is to add them individually and then separate them by a comma that's all we have to do in fact if you go down a bit further you can see we can add even more stuff but in our case that's not too important which means back inside of our python file what we want to do is print something like hello S1 string then comma and then another string with have a nice day smiley face if I now run the code we get what is your name let's say Bob again and we get hello Bob have a nice day also notice here if you are separating these values by a comma python or the print state is automatically adding one wi space between the values so you don't have to do it yourself and well with that we have covered lots of basic parts of python for the next part we are going to look at how to manipulate values I'll see you there

Original Description

In this Python crash course tutorial series, you'll learn all the basics of Python from the ground up. 🚀🥷🏼Get access to the Python Crash Course on Net Ninja Pro: https://netninja.dev/p/python-crash-course 🔥🥷🏼 Access Premium Courses with a Net Ninja Pro subscription: https://netninja.dev/p/net-ninja-pro/ 🔗🥷🏼 Check out Clear Code for more of his own tutorials: https://www.youtube.com/c/ClearCode 🔗🥷🏼 VS Code - https://code.visualstudio.com/
Watch on YouTube ↗ (saves to browser)
Sign in to unlock AI tutor explanation · ⚡30

Playlist

Uploads from Net Ninja · Net Ninja · 0 of 60

← Previous Next →
1 Regular Expressions (RegEx) Tutorial #14 - Matching a Username
Regular Expressions (RegEx) Tutorial #14 - Matching a Username
Net Ninja
2 Regular Expressions (RegEx) Tutorial #15 - Email RegEx Pattern
Regular Expressions (RegEx) Tutorial #15 - Email RegEx Pattern
Net Ninja
3 Regular Expressions (RegEx) Tutorial #16 - Finishing Touches
Regular Expressions (RegEx) Tutorial #16 - Finishing Touches
Net Ninja
4 GraphQL Tutorial #1 - Introduction to GraphQL
GraphQL Tutorial #1 - Introduction to GraphQL
Net Ninja
5 GraphQL Tutorial #2 - A Birdseye View of GraphQL
GraphQL Tutorial #2 - A Birdseye View of GraphQL
Net Ninja
6 GraphQL Tutorial #3 - Project (stack) Overview
GraphQL Tutorial #3 - Project (stack) Overview
Net Ninja
7 GraphQL Tutorial #4 - Making Queries (front-end preview)
GraphQL Tutorial #4 - Making Queries (front-end preview)
Net Ninja
8 GraphQL Tutorial #5 - Express App Setup
GraphQL Tutorial #5 - Express App Setup
Net Ninja
9 GraphQL Tutorial #6 - Setting up GraphQL
GraphQL Tutorial #6 - Setting up GraphQL
Net Ninja
10 GraphQL Tutorial #7 - GraphQL Schema
GraphQL Tutorial #7 - GraphQL Schema
Net Ninja
11 GraphQL Tutorial #8 - Root Query
GraphQL Tutorial #8 - Root Query
Net Ninja
12 GraphQL Tutorial #9 - The Resolve Function
GraphQL Tutorial #9 - The Resolve Function
Net Ninja
13 GraphQL Tutorial #10 - Testing Queries in Graphiql
GraphQL Tutorial #10 - Testing Queries in Graphiql
Net Ninja
14 GraphQL Tutorial #11 - GraphQL ID Type
GraphQL Tutorial #11 - GraphQL ID Type
Net Ninja
15 GraphQL Tutorial #12 - Author Type
GraphQL Tutorial #12 - Author Type
Net Ninja
16 GraphQL Tutorial #13 - Type Relations
GraphQL Tutorial #13 - Type Relations
Net Ninja
17 GraphQL Tutorial #14 - GraphQL Lists
GraphQL Tutorial #14 - GraphQL Lists
Net Ninja
18 GraphQL Tutorial #15 - More on Root Queries
GraphQL Tutorial #15 - More on Root Queries
Net Ninja
19 GraphQL Tutorial #16 - Connecting to mLab
GraphQL Tutorial #16 - Connecting to mLab
Net Ninja
20 GraphQL Tutorial #17 - Mongoose Models
GraphQL Tutorial #17 - Mongoose Models
Net Ninja
21 GraphQL Tutorial #18 - Mutations
GraphQL Tutorial #18 - Mutations
Net Ninja
22 GraphQL Tutorial #19 - More on Mutations
GraphQL Tutorial #19 - More on Mutations
Net Ninja
23 GraphQL Tutorial #20 - Updating the Resolve Functions
GraphQL Tutorial #20 - Updating the Resolve Functions
Net Ninja
24 GraphQL Tutorial #21 - GraphQL NonNull
GraphQL Tutorial #21 - GraphQL NonNull
Net Ninja
25 GraphQL Tutorial #22 - Adding a Front-end
GraphQL Tutorial #22 - Adding a Front-end
Net Ninja
26 GraphQL Tutorial #23 - Create React App
GraphQL Tutorial #23 - Create React App
Net Ninja
27 GraphQL Tutorial #24 - Book List Component
GraphQL Tutorial #24 - Book List Component
Net Ninja
28 GraphQL Tutorial #25 - Apollo Client Setup
GraphQL Tutorial #25 - Apollo Client Setup
Net Ninja
29 GraphQL Tutorial #26 - Making Queries from React
GraphQL Tutorial #26 - Making Queries from React
Net Ninja
30 GraphQL Tutorial #27 - Rendering Data in a Component
GraphQL Tutorial #27 - Rendering Data in a Component
Net Ninja
31 GraphQL Tutorial #28 - Add Book Component
GraphQL Tutorial #28 - Add Book Component
Net Ninja
32 GraphQL Tutorial #29 - External Query File
GraphQL Tutorial #29 - External Query File
Net Ninja
33 GraphQL Tutorial #30 - Updating Component State
GraphQL Tutorial #30 - Updating Component State
Net Ninja
34 GraphQL Tutorial #31 - Composing Queries
GraphQL Tutorial #31 - Composing Queries
Net Ninja
35 GraphQL Tutorial #32 - query variables
GraphQL Tutorial #32 - query variables
Net Ninja
36 GraphQL Tutorial #33 - Re-fetching Queries
GraphQL Tutorial #33 - Re-fetching Queries
Net Ninja
37 GraphQL Tutorial #34 - Book Details Component
GraphQL Tutorial #34 - Book Details Component
Net Ninja
38 GraphQL Tutorial #36 - Styling the App
GraphQL Tutorial #36 - Styling the App
Net Ninja
39 GraphQL Tutorial #35 - Making a Single Query
GraphQL Tutorial #35 - Making a Single Query
Net Ninja
40 Build Apps with Vue & Firebase - Udemy Course
Build Apps with Vue & Firebase - Udemy Course
Net Ninja
41 Updated Vue & Firebase Course (Udemy)
Updated Vue & Firebase Course (Udemy)
Net Ninja
42 Vue & Firebase Real-time Chat (Preview) #1 - Intro
Vue & Firebase Real-time Chat (Preview) #1 - Intro
Net Ninja
43 Vue & Firebase Real-time Chat (Preview) #2 - Project Structure
Vue & Firebase Real-time Chat (Preview) #2 - Project Structure
Net Ninja
44 Vue & Firebase Real-time Chat (Preview) #3 - Firestore Setup
Vue & Firebase Real-time Chat (Preview) #3 - Firestore Setup
Net Ninja
45 Vue & Firebase Real-time Chat (Preview) #4 - Welcome Screen
Vue & Firebase Real-time Chat (Preview) #4 - Welcome Screen
Net Ninja
46 Vue & Firebase Real-time Chat (Preview) #5 - Props in Routes
Vue & Firebase Real-time Chat (Preview) #5 - Props in Routes
Net Ninja
47 Vue & Firebase Real-time Chat (Preview) #6 - Route Guards
Vue & Firebase Real-time Chat (Preview) #6 - Route Guards
Net Ninja
48 Vue & Firebase Real-time Chat (Preview) #7 - Chat Window
Vue & Firebase Real-time Chat (Preview) #7 - Chat Window
Net Ninja
49 Vue & Firebase Real-time Chat (Preview) #8 - New Message Component
Vue & Firebase Real-time Chat (Preview) #8 - New Message Component
Net Ninja
50 Object Oriented JavaScript Tutorial #1 - Introduction
Object Oriented JavaScript Tutorial #1 - Introduction
Net Ninja
51 Object Oriented JavaScript Tutorial #2 - Object Literals
Object Oriented JavaScript Tutorial #2 - Object Literals
Net Ninja
52 Object Oriented JavaScript Tutorial #3 - Updating Properties
Object Oriented JavaScript Tutorial #3 - Updating Properties
Net Ninja
53 Object Oriented JavaScript Tutorial #4 - Classes
Object Oriented JavaScript Tutorial #4 - Classes
Net Ninja
54 Object Oriented JavaScript Tutorial #5  - Class Constructors
Object Oriented JavaScript Tutorial #5 - Class Constructors
Net Ninja
55 Object Oriented JavaScript Tutorial #6 - Class Methods
Object Oriented JavaScript Tutorial #6 - Class Methods
Net Ninja
56 Object Oriented JavaScript Tutorial #7 - Method Chaining
Object Oriented JavaScript Tutorial #7 - Method Chaining
Net Ninja
57 Object Oriented JavaScript Tutorial #8 - Class Inheritance
Object Oriented JavaScript Tutorial #8 - Class Inheritance
Net Ninja
58 Object Oriented JavaScript Tutorial #9 - Constructors (under the hood)
Object Oriented JavaScript Tutorial #9 - Constructors (under the hood)
Net Ninja
59 Object Oriented JavaScript Tutorial #10 - Prototype
Object Oriented JavaScript Tutorial #10 - Prototype
Net Ninja
60 Object Oriented JavaScript Tutorial #11 - Prototype Inheritance
Object Oriented JavaScript Tutorial #11 - Prototype Inheritance
Net Ninja

This video series teaches Python basics, including data types, variables, and basic operations, and provides hands-on experience with tools like Visual Studio Code and Python.

Key Takeaways
  1. Create a new Python file in Visual Studio Code
  2. Print text to the console using the print function
  3. Add comments to code using the # symbol
  4. Create variables and assign values
  5. Use parentheses to prioritize operations
  6. Get user input using the input function
  7. Store user input in a variable
  8. Print user input
💡 Using descriptive variable names and following best practices for code organization can make Python code more readable and maintainable.

Related Reads

📰
AI Tool Scorecard: 5 Dimensions EU SMEs Miss Before Signing
Learn the 5 key dimensions EU SMEs often overlook when evaluating AI tools before signing a contract, and how to create a scorecard to make informed decisions
Dev.to AI
📰
Aplikasi AI Harian Untuk Produktivitas, Bye Burnout!
Boost productivity with daily AI applications and say goodbye to burnout by leveraging tools like ChatGPT, Notion AI, and Canva AI
Medium · AI
📰
From stethoscopes to source code:Why I Switched from Pre Med to BS AI
Learn how to transition from a pre-med background to a career in AI, and why making this switch can be a great opportunity for growth and development
Medium · Programming
📰
Ilios Software Pvt. Ltd.: Building Practical AI Products That Solve Real Problems
Learn how Ilios Software Pvt. Ltd. builds practical AI products that solve real problems, and why this matters for businesses today
Medium · AI
Up next
How I use OpenAI to structure ad data and show my team what matters
Josiah Roche — Google Ads + SEO Training
Watch →