Python Basics- Operations

Code effortlessly

Before you start learning basic operations you need to realize that python has its own style. Many coders find the indentation style of python very uneasy because their eyes try to find the curly braces ‘{}’ or semi colon ‘;’ at the end of the command or statement.
If you are not aware of Pycharm Editor you can through this article.

Let us get started:

  1. Open python console in your Pycharm editor as shown in the figure.

2. Since python is an interpreted language we can add two number with ease in the console.

3. Similarly we can try different operators and see the results. Let me show you.

%’ operator is used to get the remainder of the division.

4. We can assign a value to variable via ‘=’ operator.

5. ‘==’ , ‘< =‘, ‘> =’, ‘>’,’<’, are comparison operators. Let me give you some examples to demonstrate how they work.

The variable ‘a’ whose value we assigned as 4 in the 4th step can be compared with other values. In the first command when we used ‘==’ operator which implies we are asking python to check whether the variable ‘a’ is same as 4; python finds the value as four so it returns ‘True’ as output.
These comparison operators are very useful while adding logical points in the code flow.

6. String operations:
Just like we can assign a number to a variable, we can assign a string as well.

7. Let us see how we can work with strings.
Concatenation operation — ‘+’ operator is used for concatenating two different strings.

Length of string can be found by using len() command.

Indexing — We can parse a string or get substring.
It is done by using Var[start:end] notation. ‘Var’ is the variable, start is the first character position and end is last character position.
Note:-
1.Python indexing start from 0 instead of one.
2. End value is excluded in Var[start:end] notation.
For example b[:4], the substring will get 0,1,2,3 position characters from original string ‘b’.
We can also start indexing from last character using negative indexing. Last character in a string has -1 position.

Formatting a string — We can have variables included within the string. To mark the place where the value has to be kept ‘{}’ are used.

I am confident that after going through the article you are now comfortable using basic operators and python console.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store