Python Fundamentals

Question: What are the fundamentals of the Python Programming Language?

Answer: It is an object oriented programming language that doesn't have compulsory variable declaration.
We will discuss the fundamentals of every portion of programming in general and Python in particular when we reach there. This post is about the very basics of the language.

Python Character Set 

The Python Character Set contains the
  • Letters of the English language A-Z, a-z.
  • Digits 0-9
  • Special Symbols #,&,%,$,_ etc
  • White Spaces tab=\t, Carriage Return =\r, Newline = \n and so forth
  • Other characters = all Ascii and Unicode characters
Please remember that we are not enumerating all the characters of the Python programming language here. That can be discovered elsewhere and is not relevant to our purpose which is learning the skills of programming in Python.

Token

Tokens are the smallest meaningful part of a program. Consider the following program sample:
for i in range(10):
What are the tokens here?
The tokens are for, i, in, range, ( , 10, ) and ;. The word for is a token, the letters f,o,r are not, for is meaningful, its parts are not.

Tokens the smallest meaningful part of  a program. For example.

Keywords

Keywords of a language are words that have a specific meaning in the language and cannot be used for any other purpose.
The Python keywords are

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

As you can see we have 33 keywords.

Identifier

Identifier is a programmer defined name. The programmer gives names to variables, classes, functions etc.
These are the rules for giving  valid names to identifiers.

  • Is made of letters and digits and Underscore _
  • Must start with letter or underscore
  • No other characters are allowed
  • Keywords are not allowed
  • Uppercase and lowercase are different

Literals.


Literals have the same symbol and values. for example 2 looks and has value 2, apple looks apple and is apple. x=2. Looks x and has value 2 so not a literal.

Types of literals.


Strings. Single line strings are enclosed in " double quotes or ' single quotes. If the string starts with double it should end with double. Same for single.
Multiline String have ''' or """.
s="""

This 
is
multiline
"""
print(s)
print(len(s))
Numeric literals
Integer. Examples 10, -10, +10
Float literals
Simple 1.2, 3.0, -9.6, 
Exponent Forms.
 Program Sample
n=1000
print(n)
n=1e3
print(n)
n=0.0001
print(n)
n=1e-4
print(n)
    
Varanasi Software Junction: Numerical Tokens Output



Fractional form.
Program Sample
n=5/6
print(n)
n=1/1e-3
print(n)
Varanasi Software Junction: Fraction Numerical Token






Complex Numbers

Complex have the j symbol for square root of -1
Program Sample
c=-0 + 1j
print(c)
m=c*c
print(m)



Boolean literals are True and False.

A special literal.

None

Program Sample
d={}
x=d.get(9)
print(x)
Answer will be None
Literal collections are collections of literals.



Post a query/clarification or a homework

Click Here


Post a Comment

0 Comments

Me