fbpx

Python Syntax and Data types

Today we are going to see about Python Syntax and Data types which consist of the following

  1. Python Syntax
  2. Indentation in Python
  3. Best practices while writing Python program
  4. Data types (In build data types in Python)

Code Repo : https://git.io/JtUqQ

Slides : https://git.io/JtUZM

In case if you have missed our previous topics

  1. Python introduction in Tamil Part 1
  2. Python introduction in Tamil Part 2
  3. Writing your first python program and how to execute it?

Watch in youtube: https://youtu.be/ftaMRl8gdZ0

Learn Python in Tamil | பைதான் மொழியைக் கற்றுக்கொள்ளுங்கள் – Writing first program in Python and executing them using Python Interpreter

Syntax, Indentation and Best practice

Indentation is it really needed for Python?

Well to answer for it, Yes Its is very important for us to know about the indentation. because Python does not uses the curley braces ‘{‘ or ‘}’ for enclosing the statements. where as it used the indentations for it.

Key points to remember about Indentation

  • Giving space or tab space at beginning of a line, is called indentation.
  • In Python Indentation plays important role.
  • It uses the space to determine the block of statements.
  • The first line of Python code should not have indentation.(it will throw IndentationError)

Python coding best practices

Lets us see some best practices to be followed while writing Python, these best practices are followed so that your code does not end up having errors, easy to read and understand the code or the logic.

Python Indentation Rules

  • We can’t split indentation into multiple lines using backslash.
  • The first line of Python code can’t have indentation, it will throw IndentationError.
  • You should avoid mixing tabs and white spaces to create indentation. It’s because text editors in Non-Unix systems behave differently and mixing them can cause wrong indentation.
  • It is preferred to use white-spaces for indentation than the tab character.
  • The best practice is to use 4 white-spaces for first indentation and then keep adding additional 4 white-spaces to increase the indentation.

We will have another exclusive video coming up on the topic “Python coding best practices”.

Save the above file in any folder with the name helloworld.py

.py is the file extension used to identify the file is Python script

Python Data types

In Python we have the following in-built data types.

CategoryData typesNotes/Description
Text typestrString type, which is enclosed with double quotes
Example "Hello", "Python", "Programming"
Numeric typeint, float, complexnumbers, decimal and real numbers
Sequence/Collection typelist, tuple, rangeCollections, group of items.
Mapping typedictdictionary type which has key and value pair combination.
Example: {"virus_id":20190101, "virus_name":"COVID19", "isSpreadable":True}
Set typeset, frozensetSimilar to the list, just that it excludes any duplicates and it sorts the items using natural sorting order i.e., ascending order.
Boolean typeboolTrue or False its that simple.
Binary typebytes, bytearray, memoryviewFile reading and writing we can use the bytes or bytearrays.
memory view is to view the byte location in the memory.
Python in-built data types

Watch youtube video for Python datatype and syntax in tamil https://youtu.be/ftaMRl8gdZ0

Topics discussed in the Video:
1. Python Syntax
2. Indentation in Python
3. Best practices while writing Python program
4. Data types (In build data types in Python)
------------------------------------------------------------------
Demo code : https://git.io/JtUqQ
Slides : https://git.io/JtUZM

-------------------------------------------------------
Syntax, Indentation and Best practice
------------------------------------------------------
1) Giving space or tab space at beginning of a line, is called indentation.
2) In Python Indentation plays important role.
3) It uses the space to determine the block
of statements.
4) The first line of Python code should not have indentation.(it will throw IndentationError)

Python Indentation Rules

1) We can’t split indentation into multiple lines using backslash.
2) The first line of Python code can’t have indentation, it will throw IndentationError.
3) You should avoid mixing tabs and white spaces to create indentation. It’s because text editors in Non-Unix systems behave differently and mixing them can cause wrong indentation.
4) It is preferred to use white-spaces for indentation than the tab character.
5) The best practice is to use 4 white-spaces for first indentation and then keep adding additional 4 white-spaces to increase the indentation.
-------------------------------------------------------------------------------
Python Data types:

In Python we have the following in-built data types
----------------------------------------------------------------------
Data types                                       Category
str                                                    # Text Type
int, float, complex                         # Numeric Types
list, tuple, range                            # Sequence Types / Collection
dict                                                 # Mapping Type (Key, Value Pair)
set, frozenset                               # Set Types
bool                                                # Boolean Type True | False
bytes, bytearray, memoryview   # Binary Types

#Python #Syntax #Indentation #BestPractice #PythonDataTypes
https://bit.ly/aryanz-youtube
Subscribe to out channel for more videos – https://bit.ly/aryanz-youtube
Share This