Learn Python basic commands coding for beginners


Python Basic Commands for Beginners

In this article we will be discussing about the python basic commands especially for the beginners.Here you will learn about following python commands or topics
                             Download Link At the Bottom

S. No.
Topics
1
Python Character set
2
Tokens
1)      Keywords
2)      Identifiers
3)      Literals
4)      Operators
5)      Punctuators
3
Components of a python program
1)      Expression
2)      Statements
3)      Comments
4)      Functions
5)      Blocks and Indentations
6)   Variables

1.) Python Character Set

A character set in python represents any letter , digit or any other symbols .
Python support unicode encoding.
Python has following Character sets
  • Letters
  • Digits
  • Special Symbols    (like +-/*_><@#%^&| etc )
  • White Spaces    (like blank space , tabs etc )
  • Other Characters

2.) Tokens

The Smallest Individual unit in a program is know as a Token or a lexical unit.
Python has following five tokens :-
  • Keywords
  • Identifiers
  • Literals
  • Operators
  • Punctuators
Now we shall discuss these five token one by one 


i}  Keywords

A keyword in python is a word having special meaning to the lanuguage interpreter reserved by the programming language.
These keywords can never be used as identifiers in a program code otherwise the interpreter will raise an error.
Python has following keywords

Learn Python basic commands coding for beginners

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

ii}  Identifiers

Identifiers are the user-defined names given to a part of a program like for variables,funtions,object.classes,lists,dictionaries etc
And are used as the general teminology for the names given to diffrent part of a python program.
There are Certain rules for defining an identifiers and these are :-

  • An identifiers must be made up of only Letters , digits and underscore ( _ ) symbol.
  • Digits can not be the first character of a python identifier.
  • Lower and Upper case letters are diffrent.
  • An Identifier must not be a keyword.
  • An identier can not contain any symbol other than underscore sign
  • Identifiers can be of unlimited length.
Here are some valid and invalid Identifiers :-
These tables are not properly seen on mobile phones , so you can set the site as desktop site or you can download the file of notes from the link given at the bottom of the page.

Valid Identifiers
Invalid Identifiers
ChammyCode
Date
_Coding
Chammy007
Python_Basics
Python_SDFGGSD545
_Learn_Python38
Date-Day                   {Contain hyphen (-) a special character }
ChammyCode.com    {Special Character dot (.) }
from                           {  A keyword }
None                          {    A keyword }
38Chammy                { Starting with Digit }

iii} Literals

Generally literals are referred to as constant values.
Literal are the data items that have a fix or constant values.
Python has following Literals :-

  • String literal
  • Numeric literal
  • Boolean literal
  • Special literal
  • Literal collecitons
Now first we discuss about them before moving to the next topic
so,

A] String literal
In python, string literal is formed by enclosing text in quotes i.e., both the quotes single quotes and double quotes.
Or 
A string literal is a sequence of character surrounded by quotes.
In python the string generally turned to green colour.
now some examples of string
'Python code'
'learn python'
'01-01-2021'
'ch@myc0de'
'LIt$ra1'

Python also allow the user to have certain nongraphic-characters in string values.
Nongraphic-characters are those characters which can not be typed directly from your keyboard. For example tabs,backspaces,carriage return etc.
In python these characters are represented using escape sequences.
An escape sequence is represented by a backslas ( \ ) followed by one or more characters.

Following are the escape sequences present in python :-

These tables are not properly seen on mobile phones , so you can set the site as desktop site or you can download the file of notes from the link given at the bottom of the page.
Escape Sequence
What it create
(Non-graphic Charater}
Escape Sequence
What it create
(Non-graphic Charater}
\\
Backslash ( \ )
\r
Carriage return
\’
Single quote ( ‘ )
\t
Horizontal tab
\’’
Double quote ( ‘’ )
\uxxxx
Character with 16-bit hex value
\a
ASCII Bell
\Uxxxxxxxx
Character with 32-bit hex value
\b
ASCII Backspace
\v
Vertical tab
\f
ASCII formfeed
\ooo
Character with octal value ooo
\n
New line Character
\xhh
Character with hex value hh
\N
Character named name in the Unicode database



String are of two types in python :-
(i) Single line string or Basic String
String formed by enclosing the text in single or double quotes are called single line string.
for example
text1='Learn Python'   ( in single quotes )
or  
text2="Python code"   ( in double quotes )

Single line string should end in one line only otherwise it will give an error

(ii) Multiline String
Multiline string can be created in two ways :-
a) By adding a backslash 
Please note that do not indent when conitinuing typing in the next line.
for example :- 
text3 = 'Learn\
python'

b) By using Triple quotes (''' ''')
By using triple quotes there is no need of backslash at the end of the line.
for example:-
text4=''' Learn Python 
basic commands 
coding for beginners'''


B] Numeric Literal
The numeric literal in python has following numeric types:-
1.) int (signed integers)
2.) float (floating point real values)
3.) complex (complex numbers)

Now we can discuss this numeric types one by one starting with the signed integers

i} integer literals
Integer literal in Python is generally a whole number without any fractional part and integer literal constant must have at least one digit and do not contain any decimal point . 
It can be contain either urinary plus(+) for urinary minus (-) sign.
A number with no sign is generally assumed to be positive and we cannot put commas between the numbers.

Integer literals in Python are of three types :-
a]Decimal integer literals
b]Octal integer letters
c]Hexadecimal integer literals

ii} floating point literals
Floating point literals are also called real literals.
Real literals in Python are the numbers having fractional parts.
In Python floating point literals can be write in two forms given below :-
a} fractional form
In Python real literals in fraction form generally contain at least one digit with decimal point either before or after it.
Given below are the examples of valid real literals in fractional form in Python :-
2.0 , 3.141 , 6.023 , -0.625
.3   (it will represent 0.3 in Python)
7.  (it will represent 7.0 in Python)

iii} complex 
Complex numbers in python are of form a+bj where a and b are floats and j or you can write J represents √(−1)
a is real part of number where as b as the imaginary part.

b} Exponent form
In Python a real literal in exponent form has two parts : mantissa and exponent
The Mantissa must be integer or a proper real constant .
The mantissa is followed by letter E or e and the exponent .
The exponent must be integer.
The sign of integer can be positive or negative if the user doesn't give the sign then default it is taken as positive.
Given below are the examples of real literal in exponent form in Python :-
6.023e23 , 1.6E-19 , 3.e3

C] Boolean Literal
A boolean literal in python is used to represent the Boolean values.
True and False are the only two boolean literal values in Python.
A boolean literal can either have value as True (Boolean True) or as False (Boolean False).

D] Special literal
Python also provide a special literal which is None
The None literal in Python is used indicate that something that has not yet been created, in simple words or the absence of value
It is also used to indicate the end of lists in Python. Also the None literal can be used where you have to give something but that should not have any logic.

E] Literal collections
Python also supports provide some literal collections these are generally the lists tuples sets etc.
These are very vast topics so we will discuss them in our next articles one by one with full details.

iv} Operators

What are operators?
In Python operators are the tokens that trigger some computation/action when applied to variable and other objects in an expression.
The variables audio objects to which the computation is to be applied are called operands and for the computation operators are required.
Generally operators are of two types which then contain many subtypes the two two main types are :-
A] Unary operators
In Python unary operators are the operators that require only one operand to operate upon them.
B] Binary operators
In Python binary operators are the operators that require two operands to operate upon them.
Binary operators has 8 subtypes :-
  • Arithmetic operators 
  • Bitwise operators 
  • Shift operators 
  • Identity operators 
  • Relational operators 
  • Assignment operators 
  • Logical operators 
  • Membership operators

v} Punctuators

 Punctuators are the symbols that are used in Python to indicate the rhythm and emphasis of expression or  organise programming sentences and program structure.
Given below are some mostly used Punctuators of Python programming :-
' " @ # / \ [ ] ( ) : ; = ` { } . , etc

3.) Components of a python program

What is a program ?
A program is a set of commands,instructions, statements , expressions to perform a specific task.
In python when we write a program code we can not write it in simple english language , we have to use the terminology of python , python way of coding so that it work properly.
A python program consists of various components:-
Comments,Functions,Statements,Blocks,Indentations,expressions,
variables, keywords,literals,identifiers,literal collecitons and many more .


Now we shall discuss these components one by one.


{i} Comments

What are comments ?
Comments are the addtional readable information given with code to clarify the working of code.
During the interpretation of code firstly these comments are removed by the interpreter because these are only for the user to understand what's the code is for.

In python , Comments are of two types :-
  • Single-line comments
  • Multi-line comments
Single-line comments
In python, a single line comments begins with the pound or hash character ( # ) and it ends with the end of physical line.
Single line comments are red in colour.
A physical line is the one complete line that you see on a computer.
In python, The Line length should be maximum 79 characters.
Single line comments are also of two types:-
  • full line comments
  • inline comments
In full line comments the physical line begins with a hash charater
and ends till the end of physical line.
for example
Learn Python basic commands coding for beginners
# Python coding is the easiest coding
# Python basic commands for beginners
In inline comments the comments start in between the physical line and ends till the end of physical line.
for example
if k==0 :   # Not a prime number

Multi-line Comments
In python multiline string begins with triple quote and ends also with triple quote.
Triple quote comments are very helpful in explaning a detailed project or program code.

Triple quote comments are green in colour similar to the strings.
The comments written in triple quotes or triple apostrophe (‘’’ ‘’’) are called doc strings.
for example :-
''' Learn Python basic commands 
coding for beginners.
python coding is the simplest coding. '''

{ ii } Statement

What is a statement ?
In python , a statement is a programming instruction that does something i.e., perform some action.
In python when a statement is executed it may or may not yield a value.
For example :-
print(‘Learn python basic commands for beginners’)       
# this statement calls print function
c=25                       # this statement does not yield a value
print(c+25)             # this state yield a value of 50

{ iii } Expressions

What is a expression ?
In python , an expression is any legal combination of symbols that represent something or represent a value.
In python, when the expressions are evaluated they produces or yield a value.
For example :-
A=23
print(A)
(9*2)/3

{ iv } Functions

What is a function ?
A function is a code ,a part of your program that has a name and can be reused (executed ) again and again by specifying its name in the program, whenever needed.
The functions are created using inbuilt def keyword.
Functions is also a big part of python programming , so we will discuss this in detail in our upcoming articles.

{ v } Blocks and indentations

What are blocks ?

The group of one or more statements which are part of another statement or a function is called block or code-block or suite in python.

Python uses indentations to create blocks of code.
The statements which are at same indentation level are part of same block or suite in python.
The default indentation is of 4 spaces in python.
Unnecessarily indentation of a statement , will produce an error in python
For example :-
def agesystem(x):
                ifx<18 :
                                print(‘Teenager’)
                elif18<x<60 :
                                print(‘Adult’)
                elif x>60 :
                                print(‘Senior citizen)
                else:
                                print(‘you entered wrong value’)



{ vi } Variables

What are variables ?
In python, Variables are the named locations whose values can be used and processed during program run.
Python variables are created by assigning a value of specific type whose type is to be created. like numeric variable,string variable.
To create a numeric variable we have to assign a numeric value to a variable.similarly , to create a string variable we have to assign a string value to a variable.
for example :-
k=50                    # Here k is a numeric variable
topic='Python basic commands coding for beginners'
# here topic is a string variable
In python variable assignment is very diffrent from all the other progrmming languages.
Python supports Dynamic typing.
In dynamic typing , A variable which is pointing to a value of certain type can be altered and made to point a value of diffrent type.
for example:-
k=50                                           # firstly k is a numeric variable
k='Python basic commands      # now k is a string variable

Python also supports multiple assignments.
Multiple assignments can be made in two ways in python.
(a) Assigning same value to multiple varibles.
for example :-
l=m=n=20
Here all three variable l,m,n has value 20
(b) Assigning multiple values to multiple variables.
for example :-
l,m,n=1,2,3
Here all three variable l,m,n has diffrent values l has 1, m has 2 , and n has 3
Multiple assignments is very useful in shortening the code.



Download Links
To download the short compact notes of  Python basic commands click on the download button



https://drive.google.com/open?id=1qZg6hGKNqf0T5IXqdDJHj3SLZnBlY9lu

Post a Comment

0 Comments