3 Python Programming Tutorial Series: The Basics
Hello everyone, today we would be learning about another extension of the basic fundmentals in python programming. Previously we learnt about
- Numeric values
- Integers
- Floating values
- Strings and Variables
Just in case you missed the last episode you can check here
Image from Wikimedia commons
Today we'll be learning about
- Python statement
- Python operators
- Python comments
Python Statements
Python statement can be referred to as the instructions that can be executed by the python interpreter, there are two basic types of python statements, they are print and assignment. The major difference between the print statements and the assignment statements is that the print statement returns an output statement while the assignment statement only assigns a certain value to the specified variable. The assignment operator = is used to assign a value or strings to a variable.
Assignment Operator
You can see in the example above, in the first expression, the print function was used and returned the string passed through it as a visible output.
But for the second expression where i assigned the value 1 to the variable num there was no visible output, this is because it wasn't passed into the print function. It only returned an output when the variable num was passed into the print function
Python Operators
In python, Operators are special symbols used to initiate computations like in mathematics. Examples of operators are
Exponent **
Remainder or modulus %
Integer division / /
Division /
Multiplication *
Subtraction -
Addition +
These are the some of the operators in python and their operations in the order of preference. i.e when the Exponent operator comes before the Addition Operator in an expression the Exponent operator would execute first.
Most of the operators are common to us, we use them in our daily lives, so i'll only explain the once that might be a little tricky
Exponent Operator
For the Exponent operator () is used to raise a number to a specific power. As you can see in the example above 23 returned the value 8 its the same as 2 raised to the power of 3.
Integer Division
The integer division is quite similar to the normal division, but it divides and gives you the whole number excluding the remainder, you can see in the example above 25 // 4 returned 6 as the answer instead of 6 remainder 1 or 6.25, like i said it only gives the whole number. But if you use the normal division operator you'll get 6.25 as your answer.
Modulus or Remainder operator
The Modulus operator works like the Integer Division operator, it divides the two values but the only difference is that it returns the remainder of the calculation. As shown in the above example, the expression 25 % 4 returned 1 as the output.
Python Comments
Comments refer information kept or added to a python to improve readability of the code, these comments are mainly done to explain or to talk more about a block of code. Comments start with hash # followed by the texts. They can only be added at the beginning or the end of the code. Comments do not take part in the execution of the code.
Python Comments
You are advised to add comments to your code because when you come back to your 1 year old code you won't be able to get your way through it, but comments explains the code more.
Hello @richi-3! This is a friendly reminder that you have 3000 Partiko Points unclaimed in your Partiko account!
Partiko is a fast and beautiful mobile app for Steem, and it’s the most popular Steem mobile app out there! Download Partiko using the link below and login using SteemConnect to claim your 3000 Partiko points! You can easily convert them into Steem token!
https://partiko.app/referral/partiko
Hello @richi-3! This is a friendly reminder that a Partiko user has just followed you! Congratulations!
To get realtime push notification on your phone about new followers in the future, download and login Partiko using the link below. You will also get 3000 Partiko Points for free, and Partiko Points can be converted into Steem token!
https://partiko.app/referral/partiko
Congratulations @richi-3! You received a personal award!
You can view your badges on your Steem Board and compare to others on the Steem Ranking
Vote for @Steemitboard as a witness to get one more award and increased upvotes!