Friday, March 25, 2022

Operators in Python

Hello Pythonist, here in this post I wiould like to share you about the all Python operators how they can coperates on the literals and variables at different sinarios. Unlike any other Programming languages,  Python supports wide variety of operators.

  1. Logical operators
  2. Comparison operators
  3. Bitwise operators

Let's explore more ...

Logical Operators

The Python Logical operators are simple English words

  •  and
  •  or
  •  not

All these above operators returns boolean values based on the combination of operands.


Comparison operators

There are several comparison operators as >, <, >=, <=, ==, != 

Also in operators


Bitwise Operators

Binary number 0 and 1 will be used as operands bitwise operators & | ^ and ~ allow us to manipulate single bits of data and they returns 0 or 1 based on the data bit values passed.


Python Bitwise Operator
Python Bit-wise Operators


Bit shift operators

  • Left bit-shift operator <<
  • Right bit-shift operator >>

Wednesday, March 16, 2022

Python Basics Literals and Variables

Literals

Python Variables


Python can do any athematic calculations but to bring it to a meaningful representation, reusability and easy referencing a value we use variable.

Valid variable names


A variable name can be combination of letters, numbers, and underscore. The variable name must start with either letter or underscore symbol. No other symbol or numbers allowed in the first character.

Example variable names:

  
server_name
total_servers
cpu_load_average
server10_mem_size
  
The Variable name defined in lower case is different that defined with upper case, they are created at different memory locations.

  
cpu_load_average not same as CPU_load_average
mem not same as MEM
  

Invalid Variable definations


We should not use any type of operator symbols in defining the variable. Here is some variables defined throws errors
  
c@paci+y ~ not valid @ and + 
total_@f_server ~ using @ not valid
10thserver ~ initial number not allowed  
Web Server load ~ spaces are not allowed instead we can use underscores
  
Note that variable name should not be use that is a datatype in Python example : int, float cannot be used.

In Python Variables defined in the following way:
  • The variables allow you to store values
  • A variable has a valid name (letters, digits, underscore, not a reserved keyword)
  • Python is dynamically typed that means variables can be redeclared/reassigned
  • We can use shortcut operators in order to cleanly redeclare a variable 
  • We can combine text and variables using the '+' operator in the print() function
print("Product cost:"+ product_cost)


The print() function


Comments in Python

As per my observation and learnings
  • Comments allows other developers in the team understand your code
  • A comment is created by a #followed by text
  • Do not write unnecessary comments in your python program write self document code that will be better
  • A multiline comment should have a hash in front of every line

The input() function

This input function is going  to prompt the user to get the data from the console.

The input function accepts an optional parameter that can be used in order to write message before the user inputs.

The input() method returns string value. So, if we want to perform arithmetic operations, we need to cast the value first.


How the print function is printing output, just opposite to that input() function reads the data in python.

Age =input("how old are you?")

In Python3, whatever you entered as input, the input() built-in function converts it into a string.

Sunday, March 6, 2022

Introduction to Python Orientation

Python Building Blocks

Hello everyone, Python enthusiast let me start about how we began this blog, Started learning Python from Pavan we (Sujith, Purushotham) and started noting the class and then looking into several web stuff and also into Python e-books. Once we got summary thought of sharing the idea of what we had learned about each topic as one blog post. This can continue for the next students as well anyone can share this and comment on this post. this blog posts are specially intended for newly started Python  Programming. 

Re-editing : 06-Mar-2022, As I've looked at PCEP Practice exam some of the basic info that I recollected updated here in this below section.
Re-edited it on 21-03-3023 

Little about Python History

Python came from British comedy group "Monty Python" TV show. In Feb1991 Python first release version came. Python was designed and developed by Guido Van Rossum. The Python major implemented languages are: CPythonPyPyStackless PythonMicroPythonCircuitPythonIronPythonJython (Java based Python).



Who can do this Python Courses?

Python can be easy to learn! so any one can learn this!! Kids in the Schools can do projects based on Python. Create the Python Games.

There are several System integration testers, software developers, UI/web-developers and also Linux/Unix System administrators, Java Application server (WebLogic/WebSphere) administrators. Python is a flexible scripting language. Your first thought on Python what it is? Is it a program or Scripting language.

How to begin Python if I have only Windows?

On the Windows platform, you need to download Python install which includes IDE. Windows IDE is having better features like IntelliSense, auto tab completion, function tooltips for entering the number of arguments.
To know about your Python shell version use the following command
python -V
or 
python --version
Execution you can look at this

How to begin Python for Linux System Admin?

My way of preparation of Python scripting for Linux admins is simple, using Oracle VirtualBox or VMware VMplayer or VM workstation to have a Guest Linux operating system such as Ubuntu or CentOS or RHEL any flavor you like. My favorite distro is Ubuntu have a look at how did I enter into the Python shell here.

Download links:



Best practices say better to have all your script could be placed in a folder called 'bin' for shell scripts. The same way you could follow for Python scripts also make a directory named as 'pybin'.

Could you tell me the difference between Python Programming and Python Scripting?

  • One simple explanation is that with scripting the code is interpreted whereas with programming the code is compiled.
  • The primary difference between a "programming language" and a "scripting language" is that code written in a programming language needs to be compiled before it is run. Once it is compiled, it can be run any number of times.
  • Programming languages are generally faster in execution than scripting languages but are often more difficult to use and have more rigid syntax. You can generally use either of them to do pretty much anything, though each is more suited for specific applications
  • Computer programming is the process of designing, writing, testing, debugging, and maintaining the source code of computer programs. This source code is written in one or more programming languages. The purpose of programming is to create a program that performs specific operations or exhibits a certain desired behavior. Programming languages are languages that allow you to create a program by writing structured code that is read all at once by the system, checked for errors, and translated into an unreadable format that the machine can then execute.
  • Scripting languages are languages that allow you to send commands directly to a system that executes these commands. These commands are read line by line and executed. An error is issued when a line cannot be executed for any reason. A "script" is a program written to control another program or programs. The equivalent of ".BAT" files on Unix are called "shell scripts" because they define a sequence of programmed operations for the shell.
  • Python
  • VBScript
  • JavaScript
  • Bash Shell script
  • awk Script
  • Perl Script
And a small smattering of ones traditionally used with an explicit compilation step:
  • C
  • C++
  • Java

What are the differences between Compiler and Interpreter Languages?


S.No. Compiler Interpreter
1. The compiler translates the entire program in one go and then executes The interpreter takes one statement then translates it and executes it and then takes another statement
2. Compiler generates the error report after the translation of the entire program scanned Interpreter will stop the translation after it encountered the first error
3. It takes large amount of time to analyze the source code but the overall execution time is comparatively faster It takes less amount of time to analyze the source code but the overall execution time is slower
4. The program need not be compiled every time Every time higher level program is converted into a lower level program
5. Generates intermediate object code which further requires linking, hence requires more memory No intermediate object code is generated, hence are memory efficient
6. Debugging is easy Debugging is comparatively hard


Working with arithmetic operators and relational operators, Let's know about the blocks and their structuring with indentations in Python. That is what makes programmers greater disciplined code developers.

 
 x = 34 - 23            # A comment.
 y = “Hello”            # Another one.
 z = 3.45    
 if z == 3.45 or y == “Hello”:
     x = x + 1
     y = y + “ World”   # String concat.
 print x
 print y

You may be interested to have looked over the next posts :
 Hope you enjoyed this post, keep sharing with your friends write your comment about your issues and errors in Python Program or Script on Cloud or on-premises!

DevOps Foundation course

DevOps Foundation course
Join us to learn DevOps from the Beginning