Basics of Python

Python

python_logo.jpg

What is Python?

Python is an interpreted high-level general-purpose programming language. Its design philosophy emphasizes code readability with its use of significant indentation [i].
Getting started with Python is easier as compared to that of other programming languages like Java. Python has a lot of predefined libraries which makes it hot favorite for Machine Learning/ Deep Learning like cutting edge technologies.

Keyword in Python ?

. Keyword in Python are basically words that have special meaning.

import keyword
keyword.kwlist

Output: ['False', 'None', 'True', 'and', 'as', 'assert', 'async', 'await', 'break', 'class', 'continue', 'def', 'del', 'elif', 'else', 'except', 'finally', 'for', 'from', 'global', 'if', 'import', 'in', 'is', 'lambda', 'nonlocal', 'not', 'or', 'pass', 'raise', 'return', 'try', 'while', 'with', 'yield']

len(keyword.kwlist)

Output: 35

In total we have 35 keyword in Python.

Variables in Python ?

Variable acts as a container in Python to store value. Variable acts as a place holder to hold value which we can use just by referencing the variable name.
There are rules which should be followed while naming the variable and they are:

  1. Variable name should always start either with a letter or underscore.

    firstnum = 10

    No error occurred

    _firstnum = 11

    No error occurred when we define variable with start with _

    1firstnum = 12

    File "", line 1
    1firstnum = 12
    ^
    SyntaxError: invalid syntax
    Syntax error occurred when we start defining variable with start with number.

    $firstnum = 13

    File "", line 1
    $firstnum = 13
    ^
    SyntaxError: invalid syntax
    Syntax error occurred when we start defining variable that starts with special character.

  2. Keyword cannot be used to define variable name.

    if = 2

    File "", line 1
    if = 2
    ^
    SyntaxError: invalid syntax

  3. Keyword cannot contain special symbol.

    ar$a = 1

    File "", line 1
    ar$a = 1
    ^
    SyntaxError: invalid syntax

  4. Keyword in python are case-sensitive.

    a = 10
    A = 11
    a

    Output:10

    A

    Output: 11


Identifiers in Python ?

A Python identifier is a name used to identify a variable, function, class, module or other object.

I hope this blog was useful to keep up with more such amazing content do follow me.

H2
H3
H4
3 columns
2 columns
1 column
Join the conversation now
Ecency