Skip to main content

Posts

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 W...

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:  CPython ,  PyPy ...

Installing Python on Windows Machine

Hey Guys! in this post we will be exploring the Installation procedure for Python 3 on Windows 10+ version Operating System. Do I need to check anything before installation of Python? Please check the version of Python is already installed using CMD window by typing 'python -V'. Please be aware of your Operating system version by checking 'This PC' properties.  How to install Python IDE on Windows System? Step1: Download Python from Official Python website  when you visit the website it automatically detects your Operating System and shows the download link. Here it will be Windows download! Step 2: Run the exe file which was downloaded [the file name could be like Python-3.x.x-amd64.exe  ] Navigate thru all the options you wish to choose select them. Please click on 'Install Now' option. Setup progress will show the green color progressbar it should completed by 100%; that's all   3:58 Installation of Python on Windows|Mac keep looking up to 10...

AWS DevOps Engineer Online Exam Question

SRE DevOps Engineer Exam Programming Language you can select any here I've selected as Python 3 Printing Last two digits  You are given array consists of n integers. Print the last two digits of its array values.  Given Inputs  The first line of input contains an integer n, representing the number of elements in the given array.  The second line of input contains n space separated integers, representing elements of the given array.  2 25 10  Expected Output  Print the last two digits of the product of array values.  Note that you always need to print two digits. Constraints  1<=n<=100 1<=ar[i] ar[i] is the element of the array  ### YOUR TASK ### def output(arr): ### Write you code logic here ### product_arr = 1 for i in arr: product_arr*=i print("Product of ar...

Installation of Python 3 in Linux

Beliefs As our belief, every Linux flavor has Python as one of the Shell. but that shell was created long back based on the OS release time repositories. In the most common situation where built-in Python might be at Python 2.7.x version but the latest version is on Python 3.7.x. The big challenge here is 'how do I upgrade or install Python3 on Linux?' So I've chased this challenge and completed the latest version installed on my Oracle Linux box. Python 3 installation on RHELflavors How do I install Python3 latest version on Linux? Python Programming is simple and kids can learn by doing! It's capabilities to interact with machine internals and the simple structure makes easy to write and understand it. The latest Python version for download you can find from the Python official site . Here I'm installing Python3 on the Oracle Linux same steps will be followed on any RHEL flavors as well. yum -y groupinstall development yum -y install zlib-devel Note: I...

Control your PC from Python Code

Hey guys, One of the easiest programming languages in the World is our Python. Here this post is intended for those who want to learn the hacking techniques! Here I would like to share simple 4lines of Python hack tricks that make shutdown or restart your PC. The logic here is that have the function contains the CMD Command line 'shutdown' with forceful(/s) timeout as 1 minute. Shutdown logic is here... import os def shutdown(): os.system("shutdown /s /t 1") shutdown() Restart logic is here import os def restart(): os.system("shutdown /r /t 1") restart() Jump to Linux VM and same thought to execute the same script then it failed! "Must be root." The solution there you need to be superuser to shutdown your Linux machine. To have better understand about the shutdown command in Linux operating system, used the --help option. [vagrant@mydev ~]$ sudo shutdown --help shutdown [OPTIONS...] [TIME] [WALL...] Shut down the system. ...

Program Controls and loops in Python

Python Programming controls The flow of program will be controlled with conditional statements where this flow  if condition if-else condition if-elif condition while loop while - else loop for loop for with if- else loop if condition Here I would like to work on program control statements, wherein relate some operating system functionalities so that, this would give some basic prototype for the sys admin scripts. #!/usr/bin/python # This illustrate if condition # Filename : ifex.py import os d=os.listdir('/home/pavanbsd/pybin') print d f='ifex.py' if f in d: print "File exists" else: print "Not found..." if-elif-else ladder No worries, coming soon... When you need the task that need to be done repeatedly then your choice is using loops. Python provides two simple loop constructs easy to use! More powerful then other scripting compare to, it has 'else' block. while loop Understand the power of while loop,...