Skip to content

Getting Started

Using python shell

  • Open terminal (ctrl+alt+t).
  • Type:

$ python
- If you have python 3 then type:
$ python3
This will open python shell in your terminal.


Lets tryout a simple python code to print "Unlock the world of security", all you need is to use print function.

  • open terminal and type:

$ python3
>>> print("Unlock the world of security")
- In case of python 2 the above syntax will also work along with the following syntax :
$ python
>>> print "Unlock the world of security" 
The output will be displayed in the python shell as:
>>> Unlock the world of security

Basic Data Types

  • Integer eg: -4, 0, 32
  • Float eg: -44.3, 0.55, 7.0
  • Complex eg: 3+2i, 4-i, -2-3i
  • Boolean true or false
  • String eg: 'Smile', '44', 'disc0ver'

To check the datatype, python has built in function type().

>>> n=1729
<class 'int'>
<class 'str'>
<class 'float'>
Conversion to a valid datatype is possible with the help of typecasting.



These are set of characters closed with double or single quotes.


Here security is written in double quotes, hence is taken as a string.

With length as 8.

To check length, python has built-in function, len(string name).

>>> string="security"

Press enter.


Index value starts from 0.


Things to know:

Syntax for extracting a part of the string :


>>>a='I can crack your password'


It starts from 0 to 24, thus in total 25 characters.



'I can crack your password'
For only the first 5 characters.


'I can'
For the 10th character.


To Extract the characters at even indices.

To include the last character, we need to specify the ending point as 25.



'Icncakyu asod'
Python has built-in function string_name.split("").

It will split the string into substrings when it encounters the character in quotations. If nothing is specified in the quotes, then it will display error.

Example 1

If we want to separate the string into substrings, when there is a space:

>>>a.split(" ")
It will give us a list with the substrings which are separated by what is specified in quotations (here split(" ") i.e. space).


['I', 'can', 'crack', 'your', 'password']
Example 2

>>>new='safe, secure, security'


['safe', ' secure', ' security']