Hi guys in this writeup we are going to talk about python basics before starting I would like to ask you to subscribe to my youtube channel "https://www.youtube.com/channel/UC-sfqidn2fKZslHWnm5qe-A"
in this write up we are going to talk about
# first basic python program
# data types
# conditional statements
# | for loops
# | while loop
First python program
writing our first python program to write our python program we need to install python and I assume that you have python installed on your computer so it's white our python program to do so we have to open idle so open it and then there type the following code and hit enter the code will run ad give the output to you or you can watch to the video given on the top for better understanding of code only. because I am using vs code there
comments in python are used to tell about a piece of code we define comments by using # in python
so why do we use comments?
we use comments in python to ignore some parts of the code in this region so we can explain the code.
refer to the example given below:-
variables in python
in any programming, language variables act like containers that are used to store data .suppose that you have a bucket containing water/milk/oil (different types of data in programming) here we can give the bucket a name like con1 and we can use this bucket to use this liquid for later similarly in programming we have variables which are used to store data and use later
the example shows how to implement it in python
in this case, we use var1 to store that "we have a short life" and we will call the print function and pass the variable name so that we can print the data of the variable into the screen
In programming, the data type is an important concept.
Variables should store different types of data. and they do that's why we need to learn the concept of data types
The built-in datatypes python supports are:-
leave lists, tuple sets, and dictionaries for this write-up, and let's understand why we need different datatypes
data define the type of data like two quotation marks define a string and only numbers in a variable define int data and using only decimal numbers in a variable defines it as float data type
and if we want to know the type of data stored in a variable use this code
there would be times when we want to define the type of data. and this problem is solved by casting
- int() - constructs an integer number from an integer literal, a float literal (by removing all decimals), or a string literal (providing the string represents a whole number)
- float() - constructs a float number from an integer literal, a float literal or a string literal (providing the string represents a float or an integer)
- str() - constructs a string from a wide variety of data types, including strings, integer literals, and float literals "
suppose I am a firefighter what would I firstly do is if other firefighters have not made the surrounding area wet then I will make it wet so that the chances of spreading fire will decrease
here in this example, we have used a conditional statement if other firefighters have not made the area wet then do this
now let's implement conditional statements in the code
try making other programs using python conditional statements the end of this course we will also make a game using if-else conditions
More content coming soon