Python Programming Basics And Other Secrets Your Family Doesn’t Tell You
Python is a programming language created to make the learning experience easier and code shorter. Created by Guido van Rossum and initially released in 1991, the language is now almost 30 years old. Fun fact - It is even older than Java☕
Let’s talk about some Python secrets that no one tells you🤫,
- How did Python get its name?
It is actually a fun story. The inspiration for the name came from BBC’s TV Show – ‘Monty Python’s Flying Circus’, as he (Guido van Rossum) was a big fan of the TV show and also he wanted a short, unique and slightly mysterious name for his invention and hence he named it Python!
- Was Python the successor?
Yes, Python is said to have succeeded in the ABC Programming Language, which had interfacing with the Amoeba Operating System and had the feature of exception handling. The syntax of Python comes from ABC programming language and some of its good features. ABC came with a lot of complaints too, so those were fixed completely and there came a good scripting language Python that had removed all the flaws.
- How does Python work?
Python is an interpreted language and not a compiled one, although compilation is the first step. Python code, written in a .py file is first compiled to what is called bytecode which is stored with a .pyc and later executed line by line.
- Is Python really slow?
What if I tell you it is a myth? How can Python be slow when its interpreter is written in C? Yes, since it's an interpreted language, due to its nature of executing code line by line, that is what makes it slow compared to other languages like C, C++, Java, etc that are compiled languages and are known for their speed. If Python would have been that slow, then do you think it would have been used by giants like IBM, NASA, Instagram, Dropbox, and more?
😎Come on, Now you know these secrets, it’s time to amaze your family, With that said, let’s move towards the basics of Python that you should know!
1) Printing Data
It does not matter what kind of application it is, you will need to print out some data so that the user can see it. For example, if you are developing a game, you might need to print out the score.
Printing out data is quite simple in Python and a matter of just one line. Check this out, this is how it is done.
print(“Love you Python😍”)
2) Variables and Data Types
In programming, most times we need to store some data. Just like we store our clothes in the cupboard, similarly, in Python, we store data in something called variables. Variables are just like some containers that hold value, just like a cupboard.
Check out the below example, where we want to store the name of the user,
username = “John”
Here, the username is the variable name, that holds the value “username”
That said, while developing applications, we need to store different types of data into our application. Below is the list of data also called data types that are available in Python that can be used to store and manipulate data.
- String - A string is a sequence of characters, just like words
- Numeric - There are three types of numeric data in Python, Integer (Any Real Number), Floating Point (Decimal or Fractional numbers), Complex Numbers (Real and Imaginary numbers)
- Boolean - Boolean generally contains two types of values- True and False
Check this example,
firstName = “Jane” age = 20 isAdult = True
3) Decision Making
Decisions are an integral part of our life. We make decisions time and time throughout the day. Just like you made the decision to read this article. And thank you for that!🤗
Similarly, in programming, we need to make decisions based on some conditions so that the computer can execute the task accordingly.
Check this out,
age = 20 if (age > 18): print(“You are eligible to vote”) else : print(“You cannot vote”)
Looping means iterating a particular task. Consider a scenario, where you need to print “Love you Python” 100 times. Writing the print statement 100 times does not make sense, here comes looping. With the help of loops, we can iterate and execute a particular piece of code any number of times. There are mainly two types of loops in Python - The for loop and The while loop.
Check the below example of for loop to print “Love you Python” 100 times,
for i in range(100): print(“Love you Python”)
Functions are some chunks of code that are only executed when they are told to, Basically, these are the programming components that can be reused. Let’s say you want to add two numbers and it is required at different places in your code. So rather than writing simply a code to add numbers, one can create a function and call it whenever required.
Check out the below example,
def add(a, b): return a+b add(4,3) add(5,1
Congratulations, you have just learned the basics of Python! Want to dive deep into Python and become a master in Python? Try our app Programming Hero, a fun way to learn to code.