Python Beginner Tutorial #2 - Variables and Data Types
Skills:
Python for Data80%
Key Takeaways
Explains Python variables and data types including typecasting
Full Transcript
what's going on guys welcome to the second episode of the Python tutorial series for beginners in today's video we're going to talk about variables and data types now in the last episode we wrote our first hello world program and mentioned that we need to use quotation marks to define the data type of the value now all values in pythons have data types in this case it was a text value and the data type which is used for text and Python is called string it is one of the multiple data types we can choose from and it is called string because a text is actually just a string of characters so in this video we're going to get a brief overview of the different data types that Python offers and we're also going to learn how to work with variables now let us start with the data type that we already know the string the string has the keyword STR and we're going to talk about the importance of these keywords later on in this video but for now just know this string has the keyword STR and it always has to be surrounded by some kind of quotation mark so we can use double quotation marks we can use single quotation marks and we can also use a triple quotation marks if you wanted to find multi-line strings so this would be a multi-line string over multiple lines and then we closed it again with a triple quotation so this is basically our text data type next data type on our list is the integer and an integer represents a whole number so everything like 10 or 9 or also minus 3 everything that has no decimal places that's just a whole number either negative or positive is an integer so the basic number type you could say if for some reason however you need to work with decimal places you can work with floating-point numbers these have the keyword float and these are numbers like ten point nine or nine point three three four five or minus eight point seven six three whatever these are floating-point numbers and we use them if we need more precision in our calculations now with that's still not enough and you're working with some advanced mathematics Python also allows you to define a complex number so for this you use the complex function and you pass a real part like 10 for example and an imaginary part let's say 5 and this would give you a complex number that you can do calculations with so 10.5 I in this case now if you don't know how complex numbers work it doesn't matter because that's more into mathematics it's not so much programming so if you don't need it just don't use it so these are the number types but there's also a special datatype called boolean and the boolean has the keyword bool and it can only have one of two values so it can either be true with a capital T or Falls with a capital F and it's basically a binary type because it cannot be something in between it has to be either 1 or 0 on or off or true or false and so on we're going to use this datatype a lot when it comes to conditions if statements and loops and future episodes so these are the basic datatypes actually we also have some sequences like lists and tuples and dictionaries and so on but these are sequences and they will be the topic of future episodes so we're going to skip them for now so let us now talk a little bit about the importance of data types for example when we have the string 10 and the number 10 or the integer 10 these would give us the same output when we print them but they are very different and they behave differently as well when we print the result off the strings temples 10 for example let's say 10 plus 10 we would get a different result then we would get when we print the integers 10 plus 10 so let us form the script as you can see when we say 10 plus 10 in the string world it says append 1 string onto the end of another string because we have the string 10 and when we add another string 10 it just puts another string at the end of the first string however if we add two numbers of course we get the sum the arithmetic sum the result of the calculation and this somehow gets us to the next question how can we know what data type a value has will not always be able to determine it by just looking at it because sometimes the values will be stored in variables but for this we have a specific function called type the type function returns the data type of a variable or a value so let's say type 10 and this will return me the data type of this value returning means that it just gives me this data type does not mean that it prints the data type but just I get this value back so I could save it in a variable later on or I can print it so what I do here is I say give me the type of 10 and then print this result so in this case we would get class int for integer and when announced quotation marks so it's now a string when I run this I get class STR for string so if we're not sure what datatype we're dealing with we can always use the type function now let us get to the second part of this video the variables defining variables in Python is very simple we just choose a variable name like X or Y or something else and we then assign a value to it so ax could be 10 Y could be hello and whatever could be true now our variables work like placeholders so we can use them for further processing this is useful because sometimes we don't know what the value of the variable will be but we still want to perform operations on it this might be the case with user input or when we load data from the internet so I could just go ahead and say print X for example and it would out print the letter X it would print the value that's stored in X so 10 and if I print wide would give me hello and so on or if I say Y is 20 for example I can say print X plus y save it and I would get 30 so I can use variables as placeholders now python is a dynamically typed language this means that we don't have to define a specific data type for our variable in advance also our variable can change its data type all the time in other language like Java or C++ we would have to define a static data type for each variable so it would still be possible to change the value but an integer variable could not just change the value to a string in Python this is possible so we can say x equals 10 and it starts as an integer later on I can say x equals some string and then I can say x equals true and it changes not only its value but also its data type in other programming languages or in most programming languages this is not possible I would have to say something like int X and then I would have to stay in the integer realm I would have to stay with this datatype so we're now getting to the last part of this video which is about typecasting now imagine we have some user input that is of the data type string but it actually contains a number and we want to do calculations with it so for example I could say user input X equals number 120 but in a string format in this case we couldn't do any calculations with the input because when we try to divide it by and for for example let's say print X divided by 4 what I would get is a type error so as you can see type error because I cannot just use this operator for division on strings and integers so I have to have two integers or two floats two number types basically so we would have to convert the value to another data type and we do this by using the data type keywords that we mentioned in the beginning of this video so when I have the variable X and I want to get an integer out of it what I can do is I can say x equals and then I use the int function so I use the int keyword for integer and I pass to it the value of x so I have x equals into X so I get the value of X turn it into an integer and then assign it back to X now that we have done this we can do the calculation with it because you can see 120 over 4 equals 30 and it works because now we're dealing with two number types however this only works when the string really contains a number otherwise we would get a so called value error because we cannot just typecast a text into an integer so if I have x equals hello I cannot just go ahead and say typecast into int because as you can see value error I cannot just convert some letters into numbers so that's everything you need to know about variables and data types for now in the next video we're going to cover operators and user input so these will allow us to perform actions on our values and variables so keep going and watch the future episodes it will get more and more interesting over time and if you haven't done it yet subscribe to this channel if you want to see more hit the like button if you enjoyed this video and feel free to ask questions and give feedback in the comment section down below thank you very much for watching and see you in the next video bye [Music] you
Original Description
In today's episode we are talking about variables and data types. At the end, we also mention typecasting and how to convert from one data type into another.
Website: https://www.neuralnine.com/
Instagram: https://www.instagram.com/neuralnine
Twitter: https://twitter.com/neuralnine
GitHub: https://github.com/NeuralNine
Programming Books: https://www.neuralnine.com/books/
Outro Music From: https://www.bensound.com/
Subscribe and Like for more free content!
Watch on YouTube ↗
(saves to browser)
Sign in to unlock AI tutor explanation · ⚡30
Playlist
Uploads from NeuralNine · NeuralNine · 3 of 60
1
2
▶
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
Visualizing Stock Data With Candlestick Charts in Python
NeuralNine
Python Beginner Tutorial #1 - Installation and First Program
NeuralNine
Python Beginner Tutorial #2 - Variables and Data Types
NeuralNine
Python Beginner Tutorial #3 - Operators and User Input
NeuralNine
Python Beginner Tutorial #4 - If Statements and Conditions
NeuralNine
Python Beginner Tutorial #5 - Loops
NeuralNine
Python Beginner Tutorial #6 - Sequences and Collections
NeuralNine
Python Beginner Tutorial #7 - Functions
NeuralNine
Python Beginner Tutorial #8 - Exception Handling
NeuralNine
Python Beginner Tutorial #9 - File Operations
NeuralNine
Python Beginner Tutorial #10 - String Functions
NeuralNine
Python Intermediate Tutorial #1 - Classes and Objects
NeuralNine
Python Intermediate Tutorial #2 - Inheritance
NeuralNine
Python Intermediate Tutorial #3 - Multithreading
NeuralNine
Python Intermediate Tutorial #4 - Synchronizing Threads
NeuralNine
Python Intermediate Tutorial #5 - Events and Daemon Threads
NeuralNine
Python Intermediate Tutorial #6 - Queues
NeuralNine
Python Intermediate Tutorial #7 - Sockets and Network Programming
NeuralNine
Python Intermediate Tutorial #8 - Database Programming
NeuralNine
Python Intermediate Tutorial #9 - Recursion
NeuralNine
Python Intermediate Tutorial #10 - XML Processing
NeuralNine
Python Intermediate Tutorial #11 - Logging
NeuralNine
Python Data Science Tutorial #1 - Anaconda and PyCharm Setup
NeuralNine
Python Data Science Tutorial #2 - NumPy Arrays
NeuralNine
Python Data Science Tutorial #3 - Numpy Functions
NeuralNine
Python Data Science Tutorial #4 - Plotting Functions With Matplotlib
NeuralNine
Python Data Science Tutorial #5 - Subplots and Multiple Windows
NeuralNine
Python Data Science Tutorial #6 - Matplotlib Styling
NeuralNine
Python Data Science Tutorial #7 - Bar Charts with Matplotlib
NeuralNine
Python Data Science Tutorial #8 - Pie Charts with Matplotlib
NeuralNine
Python Data Science Tutorial #9 - Plotting Histograms with Matplotlib
NeuralNine
Python Data Science Tutorial #10 - Scatter Plots with Matplotlib
NeuralNine
Python Data Science Tutorial #11 - 3D Plotting with Matplotlib
NeuralNine
Python Data Science Tutorial #12 - Pandas Series
NeuralNine
Python Data Science Tutorial #13 - Pandas Data Frames
NeuralNine
Python Data Science Tutorial #14 - Pandas Statistics
NeuralNine
Python Data Science Tutorial #15 - Pandas Sorting and Functions
NeuralNine
Python Data Science Tutorial #16 - Pandas Merging Data Frames
NeuralNine
Python Data Science Tutorial #17 - Pandas Queries
NeuralNine
Python Machine Learning Tutorial #1 - What is Machine Learning?
NeuralNine
Python Machine Learning Tutorial #2 - Linear Regression
NeuralNine
Python Machine Learning Tutorial #3 - K-Nearest Neighbors Classification
NeuralNine
Python Machine Learning #4 - Support Vector Machines
NeuralNine
Python Machine Learning Tutorial #5 - Decision Trees and Random Forest Classification
NeuralNine
Python Machine Learning Tutorial #6 - K-Means Clustering
NeuralNine
Python Machine Learning Tutorial #7 - Neural Networks
NeuralNine
Python Machine Learning Tutorial #8 - Handwritten Digit Recognition with Tensorflow
NeuralNine
Generating Poetic Texts with Recurrent Neural Networks in Python
NeuralNine
Stock Portfolio Visualization with Matplotlib in Python
NeuralNine
Analyzing Coronavirus with Python (COVID-19)
NeuralNine
Making Text Images Readable Again with Python and OpenCV
NeuralNine
Neural Networks Simply Explained (Theory)
NeuralNine
Motion Filtering with OpenCV in Python
NeuralNine
Top 5 Programming Languages To Learn in 2020
NeuralNine
Simple TCP Chat Room in Python
NeuralNine
Image Classification with Neural Networks in Python
NeuralNine
Edge Detection with OpenCV in Python
NeuralNine
S&P 500 Web Scraping with Python
NeuralNine
Simple Sentiment Text Analysis in Python
NeuralNine
Introduction - Algorithms & Data Structures #1
NeuralNine
More on: Python for Data
View skill →Related Reads
📰
📰
📰
📰
Nomad AI Review 2026: Can This AI-Powered Travel Platform Help You Build an Online Business?
Medium · AI
The Only 4 Claude Prompts I Use Every Single Day
Medium · Programming
The Most Valuable Way to Use AI in Your Business Is Also the Most Boring
Medium · AI
ccpool helps you save $100 a month on claude usage
Dev.to · salah zeghdani
🎓
Tutor Explanation
DeepCamp AI