Introduction to python
Python is a high-level programming language, interpreted, interactive, and object-oriented scripting language. I have started a blog series every week I publish an article related to python. It will be helpful for the beginner.
Why Learn Python?
Python is designed to be highly readable. It uses English keywords frequently
- Python is Interpreted: You do not need to compile your program before executing it.
- Python is Interactive: you can actually sit at a Python prompt and interact with the interpreter directly to write your programs.
- Python is Object-Oriented: It supports an Object-Oriented style or technique of programming that encapsulates code within objects.
- Python is a Beginner's Language − it is a great language for beginner-level programmers.
Basic Syntax of Python
the python syntax is very simple
print("Hello world")
Data types in python
Every value in Python has a datatype. Since everything is an object in Python programming, data types are actually classes and variables are instance (object) of these classes.
The standard or built-in data type of Python:
- Numeric
- Sequence Type
- Boolean
- Set
- Dictionary
Numeric
They are defined as int, float and complex classes in Python
- Integers – It contains positive or negative whole numbers (without fraction or decimal).
- Float – It is a real number with floating point representation. It is specified by a decimal point.
- Complex Numbers – Complex number is represented by complex class. It is specified as (real part) + (imaginary part)j. For example – 2+3j
we will see detail in the next series
Sequence Type
Sequence is the ordered collection of similar or different data types. Sequences allows to store multiple values in an organized and efficient fashion.
There are several sequence types in Python –
- String
- List
- Tuple
String
A string is a collection of one or more characters put in a single quote, double-quote or triple quote. In python there is no character data type, a character is a string of length one. It is represented by str class.
List
Lists is a ordered collection of data. it is mutable that means it can be added or change after the creration of the list .it may have same data type or different data type.
Tuple
Tuple is also an ordered collection of Python objects. The only difference between tuple and list is that tuples are immutable
Boolean
Data type with one of the two built-in values, True or False. Boolean objects that are equal to True are truthy (true), and those equal to False are falsy (false)
Set
Set is an unordered collection of data type that is iterable, mutable and has no duplicate elements. The order of elements in a set is undefined though it may consist of various elements.
Dictionary
Dictionary is an unordered collection of data values, used to store data values like a map, which unlike other Data Types that hold only single value as an element, it holds key:value pair.
Key-value is provided in the dictionary to make it more optimized. Each key-value pair in a Dictionary is separated by a colon :, whereas each key is separated by a ‘comma’.
we will see detail of all datatypes with example in the next series.