Let the Python game....Beginnnn~!

ยท

4 min read

Let the Python game....Beginnnn~!

Day-1 :- Starting out

Today is 1st February 2023, which marks the beginning of my journey towards learning Python to use it effectively in the field of Data Science. I am a BCA-pursuing 21-year-old guy from India. It is a 3-year course and I am determined towards Mastering the field of Data Science and acquiring a Master's degree from the most renowned universities in the world, so I can use and share my knowledge among the best minds to utilize it towards bringing up something revolutionary. But, everyone who has brought a revolution had a small start, and I am considering this to be MY small start :) Hence, this will be a blog where I will write down my learnings as I start with Python. I hope everyone who reads this is as excited to embark on this journey as I am! HUGE thanks to

Rolo Natt

for the inspiration! :D


Python

1.1 Printing

Starting out with the most important and the hardest code of all time, printing "hello world!".

Pretty Simple:

print("hello world!")

Output: hello world! (outputs are highlighted)

We can print out all kinds of stuff using the print command as well as performing arithmetic operations within the brackets.

eg:

print(3+4)

^ the above code will return 7

BUTTTT

print("3+4")

^ this will simply return 3+4

Few more arithmetic operations include:

eg:

print(4*12)

48

and so on.


1.2 Variables

Variables are used to assign values so we can easily call them shall we later require them in the future.

For example, if I need to assign my phone number because I'll be needing it again and again, I can do:

yash_no=123456789

now the variable "yash_no" has the value "123456789" stored in it. (Not my actual number so don't try funny stuff, I know you want to)

and to print it out, I can simply type:

print(yash_no)

^ which will give us 123456789


Assigning names to a variable just has 3 simple rules which we follow, which are:

  • They can't have spaces (e.g., "yash no" is not allowed)

  • They can only include letters, numbers, and underscores (e.g., "yash_no!" is not allowed)

  • They have to start with a letter or underscore (e.g., "1_yash" is not allowed)


We can simply change the value assigned to a variable by just declaring it again.

for eg: "yash_no" has a value of "123456789"

if I just type:

yash_no=987654321

and now if we print "yash_no" variable, we will get 987654321

We can also change the values by adding or subtracting or performing any arithmetic operations on the previously defined values as well, I'll be taking a different example for this.

var=25

^ the initial declaration. Now if i wanna change it using the defined variable only, it is done by:

var=var+25

and now finally, printing "var" will give us 25+25 (var + 25), that is 50


Excercise:

Finding out how many seconds are there in 31 days.

This will make us summarize almost all of what we learned today.

Now, the logic behind finding out this is simply finding out how many seconds there are in a minute, then multiplying it by how many minutes there are in an hour, then multiplying it by how many hours we have in a day, and then finally, for 31 days, we multiply it all by 31. We have to do exactly the same in the code.

We will start by assigning values to required variables first. **(remember to assign variables one by one, you won't be able to copy the below code and paste and assign all 4 of them at once :p)**

sec_per_min=60
min_per_hr=60
hr_per_day=24
total_days=31

Now that we have variables assigned, we can use them to perform our arithmetic function.

total_sec = sec_per_min * min_per_hr * hr_per_day * total_days

and finally, we can print out the result:

print(total_sec)

^ this gives us 2678400


Anddddd, that concludes what I learned today. Pretty easy and exciting so far. Let's see what python has to teach us tomorrow!


Peace~๐Ÿ•Š๏ธ

Yash K.

ย