Question:
With a given list [5,3,5,3,6,8,3,1,9,4,5,9,0,7], write a program to print this list after removing all duplicate values with original order reserved.
Program:
1 2 3 4 5 6 7 8 9 10 11 12 |
<strong>def removeD</strong>uplicate( li ): newli=[] seen = set() for item in li: if item not in seen: seen.add( item ) newli.append(item) return newli li=[5,3,5,3,6,8,3,1,9,4,5,9,0,7] print (removeDuplicate(li)) |
Explanation:
Set() function stores number of values without duplicate.
Output:
1 |
[5, 3, 6, 8, 1, 9, 4, 0, 7] |
Question :
Swap two variables without using a third temporary variable
Program:
1 2 3 4 5 |
num1= int(input("Enter the first number:")) num2=int(input("Enter the second number:")) print "num1:",num1,"num2:", num2 num1,num2=num2,num1 print "After swap: num1:",num1,"num2:", num2 |
Explanation:
Here num1, num2 acts as a tuple. Since tuples are mutable, the above assignment works perfectly well
Output:
1 2 3 4 |
Enter the first number:8 Enter the second number:99 num1: 8 num2: 99 After swap: num1: 99 num2: 8 |
Question:
A robot moves in a plane starting from the original point (0,0). The robot can move toward UP, DOWN, LEFT and RIGHT with a given steps. The trace of robot movement is shown as the following:
UP 5
DOWN 3
LEFT 3
RIGHT 2
The numbers after the direction are steps. Please write a program to compute the distance from current position after a sequence of movement and original point. If the distance is a float, then just print the nearest integer.
Example:
If the following tuples are given as input to the program:
UP 5
DOWN 3
LEFT 3
RIGHT 2
Then, the output of the program should be:2
Program:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
import math pos = [0,0] while True: s = raw_input() if not s: break movement = s.split(" ") direction = movement[0] steps = int(movement[1]) if direction=="UP": pos[0]+=steps elif direction=="DOWN": pos[0]-=steps elif direction=="LEFT": pos[1]-=steps elif direction=="RIGHT": pos[1]+=steps else: pass print int(round(math.sqrt(pos[1]**2+pos[0]**2))) |
Explanation:
The distance formula is derived from the Pythagorean theorem. To find the distance between two points (x1,y1) and (x2,y2), all that you need to do is use the coordinates of these ordered pairs and apply the formula d=√{(x2−x1)2+(y2−y1)2}.This formula is used to find the distance.
Output:
1 2 3 4 5 6 |
UP 20 RIGHT 70 UP 20 Left 60 81 |
Question:
Write a program that accepts a sequence of whitespace separated words as input and prints the words after removing all duplicate words and sorting them alphanumerically.
Program:
1 2 3 |
s = raw_input() words = [word for word in s.split(" ")] print " ".join(sorted(list(set(words)))) |
Explanation:
The string is accepted to s and split to a list using s.split. the list is then sorted and then joined to form the output string
Output:
1 2 |
GLOBALSQL is the best place to learn to code the best GLOBALSQL best code is learn place the to |
Question:
Define a class with a generator which can iterate the numbers, which are divisible by 7, between a given range 0 and n.Use yield.
Program:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
def putNumbers(n): i = 0 while i<n: j=i i=i+1 if j%7==0: yield j for i in putNumbers(100): print i |
Explanation
The yield statement is used to define generators, replacing the return of a function to provide a result to its caller without destroying local variables. Unlike a function, where on each call it starts with new set of variables, a generator will resume the execution where it was left off.
Output:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
0 7 14 21 28 35 42 49 56 63 70 77 84 91 98 |
Question:
Write a program to sort the (name, age, height) tuples by ascending order where name is string, age and height are numbers.
1: Sort based on name;
2: Then sort based on age;
3: Then sort by score.
The priority is that name > age > score.
We use itemgetter to enable multiple sort keys.
Program:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
from operator import itemgetter, attrgetter l = [] while True: s = raw_input("Enter Details: (Name,Age,Score)[Press Enter to end\n") if not s: break l.append(tuple(s.split(","))) print sorted(l, key=itemgetter(0,1,2)) |
Explanation:
operator
is a built-in module providing a set of convenient operators. In two words operator.itemgetter(n)
constructs a callable that assumes an iterable object (e.g. list, tuple, set) as input, and fetches the n-th element out of it.
Output:
1 2 3 4 5 6 7 8 9 |
Enter Details: (Name,Age,Score)Press Enter to end Lily,19,84 Enter Details: (Name,Age,Score)Press Enter to end Tom,21,67 Enter Details: (Name,Age,Score)Press Enter to end Mark,15,86 Enter Details: (Name,Age,Score)Press Enter to end [('Lily', '19', '84'), ('Mark', '15', '86'), ('Tom', '21', '67')] |
Question:
Write a program to compute the frequency of the words from the input. The output should output after sorting the key alphanumerically.
Program:
1 2 3 4 5 6 7 8 9 10 11 |
freq = {} # frequency of words in text line = raw_input("Enter Text:") for word in line.split(): freq[word] = freq.get(word,0)+1 words = freq.keys() words.sort() print "Frequency chart" for w in words: print "%s:%d" % (w,freq[w]) |
Explanation:
The sort() method sorts the elements of a given list in a specific order – Ascending or Descending.
Output:
1 2 3 4 5 6 7 8 9 10 11 |
Enter Text:Hey There! Hello and hello and welcome to GlobalSQA Welcome Frequency chart GlobalSQA:1 Hello:1 Hey:1 There!:1 Welcome:1 and:2 hello:1 to:1 welcome:1 |
Question:
Write a program to sort the string accepted from the user
Program:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
# Program to sort alphabetically the words form a string provided by the user my_str = raw_input("Enter a string: ") # breakdown the string into a list of words words = my_str.split() # sort the list words.sort() # display the sorted words print("The sorted words are:") for word in words: print(word) |
Explanation:
The sort function returns the sorted data item.
Output:
1 2 3 4 5 6 |
Enter a string: GlobalSQA is the best! The sorted words are: GlobalSQA best! is the |
Flask is a micro web framework written in Python
Web Application Framework or simply Web Framework represents a collection of libraries and modules that enables a web application developer to write applications without having to bother about low-level details such as protocols, thread management etc.
virtualenv which is a virtual Python environment builder, is used to help a user to create multiple Python environments side-by-side. Thereby, it can avoid compatibility issues between the different versions of the libraries.
The following command installs virtualenv
1 |
sudo pip install virtualenv |
Once installed, a new virtual environment is created in a folder.
1 2 3 |
mkdir FlaskTest cd FlaskTest virtualenv Test |
So now we have a virtual environment Test created in the FlaskTest folder
We now install Flask in this environment.
1 |
sudo pip install Flask |
Now we have Flask installed in our system and we can import it in our projects.
As we have setup environment to work with Flask library, lets run a sample code to test Flask. Let’s create a python file HelloWorld.py and write the following code:
1 2 3 4 5 6 7 |
from flask import Flask app = Flask(__name__) @app.route('/') def hello_world(): return 'HELLO WORLD’ if __name__ == '__main__': app.run() |
1 |
app.run(host, port, debug, options) |
All parameters for the run function are optional
host
Hostname to listen on. Defaults to 127.0.0.1 (localhost). You have to set it to ‘0.0.0.0’ to have server available externally
port
Default value is 5000
debug
Default value is false. If it is set to true, we get debug information
options
To be forwarded to underlying Werkzeug server.
Now we can execute the program and see its working. Execute the program using the command
1 |
python HelloWorld.py |
You will get the following output.
1 |
* Running on http://127.0.0.1:5000/ (Press CTRL+C to quit) |
Now if you open your browser and type in your localhost address that is, 127.0.0.1 along with the port number 5000
You can see HELLO WORLD being printed on your browser.
You can use Ctrl+C to stop running the program.
Now if you need to set a specific URL other than the homepage of localhost, you can specify it in the route() function.
If you change the route function in the above code to:
1 |
@app.route('/hello') |
And run the program again, you can see that opening the homepage of localhost renders no output, but instead if you add the URL specified in route function to the homepage address:
Now you can see your program being run…
Have fun working with Flask library
Maintaining the backends or servers is always a part of the headache for the programer. And here walk in the solution, serverless Architectures.
It refer to applications that significantly depend on third-party services (known as Backend as a Service or “BaaS”) or on custom code that’s run in ephemeral containers (Function as a Service or “FaaS”), the best known vendor host of which currently is AWS Lambda
Using an amazing library called Zappa, it is now easy to deploy in AWS Lambda.
Zappa is a system for running “serverless” Python web applications using AWS Lambda and AWS API Gateway. It handles all of the configuration and deployment automatically . Now it is easy to deploy an infinitely scalable application to the cloud with a just single command at the least possible cost often just a small fraction of the cost of a traditional web server.
You can install zappa easily using
1 |
pip install zappa |
To install AWS command tools,
1 |
pip install --dev awscli |
So before we start using Zappa, let’s create a simple hello world website using flask and run it on our locla server
At a directory of your choice, save the following program as Prg.py
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
from flask import Flask app = Flask(__name__) @app.route('/') def index(): return "Hello world! ", 200 # We only need this for local development. if __name__ == '__main__': app.run() |
And run it on your local server using the following commands at your cmd
1 2 3 |
export FLASK_APP=Prg.py flask run |
Now check out http://127.0.0.1.5000/. You can see a simple webpage like below.
Before we get our hands on some zappa, we need to ensure we have a valid AWS account.
You can create a AWS account by following the steps one by one here.
After creating an account, run the following command to configure your AWS account in your command line and and fill in the access key id, the secret access key and the default region..
1 |
aws configure |
Let’s configure Zappa now.
Run the follwing command in your project directory
1 |
zappa init |
This creates a file named zappa_settings.json
inside our project directory with the following content.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
{ "dev": { "app_function": "Prg.app", "s3_bucket": "zappa-some-random-id", "runtime": "python3.6" } } |
Now deploy zappa using
1 |
zappa deploy |
And it’s done!!Thtat’s all it takes.!Just a single command!
To learn more of zappa, which I am sure you would want to, check out these sites:
Matplotlib is a Python 2D plotting library which produces publication quality figures in a variety of hardcopy formats and interactive environments across platforms. Matplotlib can be used in Python scripts, the Python and IPython shell, the jupyter notebook, web application servers, and four graphical user interface toolkits.
Matplotlib tries to make easy things easy and hard things possible. You can generate plots, histograms, power spectra, bar charts, errorcharts, scatterplots, etc., with just a few lines of code
For simple plotting the pyplot module provides a MATLAB-like interface, particularly when combined with IPython. For the power user, you have full control of line styles, font properties, axes properties, etc, via an object oriented interface or via a set of functions familiar to MATLAB users.
In debian or Ubuntu systems, you can install matplotlib using
1 |
sudo apt-get install python-matplotlib |
or use yum in fedora or Redhat:
1 |
sudo yum install python-matplotlib |
For more installation guidelines, check out https://matplotlib.org/users/installing.html
Let’s import matplotlib
1 |
>>> import matplotlib.pyplot as plt |
Let’s draw a simple graph
1 2 3 4 5 |
>>> plt.plot([1,2,3,4]) >>> plt.ylabel('some numbers') >>> plt.show() |
You obtain the following figure 1
How did python decide the x axis values?
If you provide a single list or array to the plot() command, matplotlib assumes it is a sequence of y values, and automatically generates the x values for you. Since python ranges start with 0, the default x vector has the same length as y but starts with 0. Hence the x data are [0,1,2,3].
Draw the graph of y=x2
Program:
1 2 3 4 5 6 7 |
>>> plt.plot([-4,-3,-2,-1,0,1,2,3,4],[16,9,4,1,0,1,4,9,16]) >>> plt.ylabel('Squares') >>> plt.xlabel('Numbers') >>> plt.show() |
Output:
Now lets say you wanted red dots instead of lines of say a graph y=5*x
1 2 3 4 5 6 7 |
>>> plt.plot([1,2,3,4], [1,4,9,16], 'ro') >>> plt.axis([0, 6, 0, 20]) [0, 6, 0, 20] >>> plt.show() |
You get the following graph
MatPlotLib is not limited to just using list. Usually it is used in combination to numpy, and hence it has varied effective uses that makes analysing large amount of data easy.
For more of matplotlib like drawing histograms or multiple graphs on a single plot etc, check out https://matplotlib.org/users/pyplot_tutorial.html
For more examples, check out https://matplotlib.org/examples/index.html
Checkout matplotlib cheatsheet at following link:
https://www.globalsqa.com/data-visualisation-in-python-matplotlib-cheat-sheet
Have fun with matplotlib!
Question:
Write a program to convert decimal to binary, octal and hexadecimal using inbuilt functions
Program:
1 2 3 4 5 6 7 |
# Python program to convert decimal number into binary, octal and hexadecimal number system # Take decimal number from user dec = int(input("Enter an integer: ")) print("The decimal value of",dec,"is:") print(bin(dec),"in binary.") print(oct(dec),"in octal.") print(hex(dec),"in hexadecimal.") |
Explanation:
A binary number is a number expressed in the binary numeral system or base-2 numeral system which represents numeric values using two different symbols: typically 0 (zero) and 1 (one). The base-2 system is a positional notation with a radix of 2.
The octal numeral system, or oct for short, is the base-8 number system, and uses the digits 0 to 7. Octal numerals can be made from binary numerals by grouping consecutive binary digits into groups of three (starting from the right). For example, the binary representation for decimal 74 is 1001010.
Hexadecimal (also base 16, or hex) is a positional numeral system with a radix, or base, of 16. It uses sixteen distinct symbols, most often the symbols 0–9 to represent values zero to nine, and A, B, C, D, E, F (or alternatively a, b, c, d, e, f) to represent values ten to fifteen.
Output:
1 2 3 4 5 |
Enter an integer: 56 The decimal value of 56 is: 0b111000 in binary. 0o70 in octal. 0x38 in hexadecimal. |
Question:
Write a program to print the nth line of the Pascal’s Triangle
Program:
1 2 3 4 5 6 7 8 9 10 11 12 13 |
def pascal(n): if n == 1: return [1] else: line = [1] previous_line = pascal(n-1) for i in range(len(previous_line)-1): line.append(previous_line[i] + previous_line[i+1]) line += [1] return line j=int(input("Enter line number:")) print(pascal(j)) |
Explanation:
Pascal’s triangle is a triangle where each number is equal to the sum of the one or two numbers above it:
Output:
1 2 |
Enter line number: 9 [1, 8, 28, 56, 70, 56, 28, 8, 1] |
Question:
Write a single line of code to print squares of numbers till 15 using lambda, map and list comprehension
Program:
1 |
map(lambda x: x*x, range(15)) |
Explanation:
The lambda operator or lambda function is a way to create small anonymous functions, i.e. functions without a name. These functions are throw-away functions, i.e. they are just needed where they have been created. Lambda functions are mainly used in combination with the functions filter(), map() and reduce().
The map function is the simplest one among Python built-ins used for functional programming. These tools apply functions to sequences and other iterables. The filter filters out items based on a test function which is a filter and apply functions to pairs of item and running result which is reduce.
So here the output of the anonymous function for squaring x when x ranges from 1 to 15 is recieved.
Output:
1 |
=> [0, 1, 4, 9, 16, 25, 36, 49, 64, 81, 100, 121, 144, 169, 196] |
Question:
Consider variable x. do the following operation. Add 2 to x and square the result. Again add 3 to x and square the result. Do using anonymous functions in python
Program:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
def func(n): return lambda x: (x+n)**2 #b is the lambda function where n = 2 and it accepts an arguement x b=func(2) print "b is a lambda function with n = 2 and type : ",type(b) #b is of the type 'function' what ever value is passed to it is #passed as x of the lambda function print "\npassing value 5 to function b and result is : ", print (b(5)) #here 5 is passed to x of lambda function c=func(3) print "\n\n\nc is a lambda function with n = 3 and type : ",type(c) print "\npassing value 5 to function c and result is : ", print (c(5)) b=5 print "\n\n\nb is now an integer with value : ",b c=4.5 print "\nc is now a float with value : ",c |
Explanation:
The lambda operator or lambda function is a way to create small anonymous functions, i.e. functions without a name. These functions are throw-away functions, i.e. they are just needed where they have been created. Lambda functions are mainly used in combination with the functions filter(), map() and reduce().
Output:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
<span class="">b is a lambda function with n = 2 and type : <class 'function'> passing value 5 to function b and result is : 49 c is a lambda function with n = 3 and type : <class 'function'> passing value 5 to function c and result is : 64 b is now an integer with value : 5 c is now a float with value : 4.5</span> |
Django is a high-level Python Web framework that encourages rapid development and clean, pragmatic design. When you’re building a website, you always need a similar set of components: a way to handle user authentication (signing up, signing in, signing out), a management panel for your website, forms, a way to upload files, etc. Python Django takes care of the repetitive work for you so that you don’t have to reinvent the wheel all over again.
You can install Django using
1 |
$pip install django |
For other ways of installation, visit this.
Since this is the first time we are using Django there is some initial setup to do. We need to auto generate some code that establishes the Django project.
From the command line,
1 |
$ django-admin startproject mysite |
This will create a folder ‘mysite ‘ in your current directory. Do avoid python names of different functionalities as names for the folder. Ex. Django and test are not good choices since they create conflict on calling.
Also, with Django you do not put your code under your web server’s root directory. We always place it outside.
Let’s look at what startproject created:
mysite/
manage.py
mysite/
__init__.py
settings.py
urls.py
wsgi.py
These files are:
Let’s verify whether our Django works.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
root@localhost:/home/enfa/Desktop/GlobalSQA/mysite# python manage.py runserver Performing system checks... System check identified no issues (0 silenced). You have 13 unapplied migration(s). Your project may not work properly until you apply the migrations for app(s): admin, auth, contenttypes, sessions. Run 'python manage.py migrate' to apply them. July 07, 2017 - 15:28:53 Django version 1.11.3, using settings 'mysite.settings' Starting development server at http://127.0.0.1:8000/ Quit the server with CONTROL-C. |
You can safely ignore the warning for now.
Yipppe! We have started the Django server! Let’s go see how it looks like.
Note This is only for studying. When it comes to production setting, use Apache servers or similar.
By default the port is 8000. But you can change it using the command line. Say you want to change it to 8080
1 |
$ python manage.py runserver 8080 |
Full docs for the development server can be found in the runserver reference
To know how to edit and configure your webpages, check out https://docs.djangoproject.com/en/1.11/intro/tutorial01/
For more details visit,
https://www.djangoproject.com/
https://docs.djangoproject.com/en/1.11/#index-first-steps
https://www.djangoproject.com/start/
https://docs.djangoproject.com/en/1.11/
https://tutorial.djangogirls.org/en/django_start_project/
Question:
Write a program to print the running time of execution of “1+1” for 100 times. Use timeit() function to measure the running time.
Program:
1 2 3 |
from timeit import Timer t = Timer("for i in range(100):1+1") print (t.timeit()) |
Explanation:
Runtime or execution time is the time during which a program is running (executing), in contrast to other program lifecycle phases such as compile time, link time and load time.
The Timer function keeps track of the time
Output:
1 |
1.8190948230039794 |
Quora brings up a lot of interesting questions from all around the world. An avid Quora reader myself, I absolutely love reading through the different questions and answers there. One of the questions that interested me was “To learn a programming language is it better to learn from a book or on-line courses on the Internet?”
Well, that answer would totally depend on how you intend to learn. If you just want to learn the syntax then some online classes would be more than fine. If you really want to learn the real power behind the language, then an in-depth online course or better you could grab a good book on it. So to all those Python learners out there, here we have compiled a list of the best python books out there for you to learn.
Written by Mark Lutz and David Ascher, Learning Python offers a comprehensive in-depth introduction to the core of Python language for any beginner. It covers basic topics of both 2.7.X as well as 3.X in much detail. Some of the topics covered are Types & Operations, statements and Syntax, Functions and Generators, Modules and packages and much more. The beginner chapter, a Q&A session on Python and especially why Python is a major highlight. The end chapter quizzes enable the reader to challenge himself on the topics covered. Therefore leaning Python is one of the best choices to get started in Python.
Written by Zed Shaw and offered for free as pdfs. Learn python the hard way will give beginners with a perfect insight to the very basics. You can also learn a variety of basic things such as how to use the terminal or the text editor. This book focuses on more on learning by doing than subject theory. therefore for an absolute beginner, Learn Python the hard way is a good choice.
Targeted for the absolute beginners in programming, author Swaroop C. H has kept it short and brief. With a user-friendly introduction, and focus on scripting simple but meaningful programs. A Byte of Python is the best choice for a beginner to learn Python briefly.
Written by David M. Beazley, this book is the perfect go to reference book on Python. All the new features such as new style classes, unification of types and classes, xmlrpclip, intertools, bz2 and optparse the new library modules are all covered in the updated edition of this book which makes it the most up-to date book on Python in the market. Written in a clear and organized manner, it gives you a detailed overview and an insight to the real power of programming. For someone with a bit of basics and want to learn Python, Python Essential Reference is a must read.
Written by David Beazley and Brian K. Jones, Python CookBook is for readers with a basic knowledge of Python. Readers who want to learn more on concepts such as data structure, data encoding and processing, functions, algorithms, classes and objects, system administration, modern tools and idioms, generators and iteration methods would find Python CookBook to be the best guide. Each recipe contains code samples written and tested in python 3.3, so that you can get to using them right away. For someone who wants to be good on Python, Python CookBook is a must read.
Authored by Claus Führer, Jan Erik Solem, Olivier Verdie, Scientic Computing in Python3 demonstrates how to use Python for computing purposes such as in linear algebra, arrays, plotting, iterating, functions, polynomials, and much more. You get to explore numerical computing and mathematical libraries with SciPy and NumPy modules. Covering all major concepts and tools in scientific computing, this book is your go to guide and best reference for the same.
Author Justin Seitz has aced how to teach security skills in python in his book Black Hat python. Targeted only for advanced Python users, this book comes as a huge boon for hackers and penetration testers to write better networking sniffers, infect virtual machines and manipulate packets and develop better hacker tools using python. A must have for any wanna be Hacker in Python.
Data Anaysis is all about collecting, cleaning, processing, crunching and studying raw data to bring out better insights on the subject matter. One of the best tools used in Python for the same is the pandas library and Wes Mckinney, one of the main authors of the pandas library has brought out a hands on book packed with practical case studies to guide you through understanding and implementing various tools and libraries used for the same. Easy to read and targeted for advanced Python users, Python for Data Analysis is your comprehensive guide to data analysis in Python.
TJ O’Connor in his book Violent Python: A Cookbook For Hackers, Forensic Analysts, Penetration Testers And Security Engineers teaches you concepts in security, hacking, forensics, tool integration for complicated protocols etc in the most simple and easy to understand style. You can also learn how to automate large network attacks, extract meta data, intercept and analyze network traffic, spoof wireless frames to attack wireless and bluetooth devices, data mine social media websites and so on. In terms of language and concepts, TJ O’Connor has aced how to teach the advanced topics in python in simple terms, bringing out the perfect go to book for the same.
Have more books to add-on to this list? Comment them below, we would love to hear from you.
Meanwhile, Have fun with Python!
Question:
Write a program implementing basic graphic functionalities such as draw,getMouse, circle etc
Program:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
from graphics import * win = GraphWin() #win is an instance of a window to display graphics content pt= Point(100,100) #pt is an object which is a Point on the screen and its co-ordinates on screen is (100,50) pt.draw(win) #the Point object pt is displayed on the screen win.getMouse() #listens for mouse click inside the window to proceed to next statement execution e = Circle(pt, 50) #e is a Circle object with centre as a Point object pt and radius 5 e.setFill('yellow') #fills blue color in the Circle object e e.draw(win) #displays the circle object win.getMouse() win.close() #closes the current GraphWin window |
Explanation:
Graphic Functionalities are implemented in python by importing graphics.py
Output:
This command is used to become another user in his own session. By default, user without username will login as super-user (i.e. Root).
1 |
su [option] – [user [arguments …]] |
1 |
$ su – guest |
1 |
$ su govind -c date |
-c option is used to return back to the command line of former user after execution is completed.
1 |
$ su – root |
1 |
$ su – |
Note: In Linux while giving password it won’t be visible because of security reason.