Siddharth Chaubey avatar

Basics of Python

sidchaubey

Published: 20 Oct 2021 › Updated: 20 Oct 2021Basics of Python

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.

Leave Basics of Python to:

Written by

Software Developer looking to give back to community by sharing my learnings everyday.

Read more #programming posts


Best Posts From Siddharth Chaubey

We have not curated any of sidchaubey's posts yet. But you can encourage our curation team to review posts by visiting them regularly and by referring other readers. Because we give priority to frequently read content.

More Posts From Siddharth Chaubey