Python isa general-purpose
high-level programming language. By using python programming language, you can design
any IT-based project easily with higher stability. Python is easy to learn and
apply. It doesn't have any include statements like the C, C++ or Java.
Importantly python is object-oriented programming from which you can interact
with real-life objects.
In Artificial
intelligence, Augmented Reality, Neural network-related projects developers choose
to program in Python. Python is also structure free language that's why it is
also called a user-friendly language because of its easy to understand by
humans. Its syntaxes are like simple English. If you are looking for Python Interview Questions then you can
visit here. This will help you to crack your interviews.
When it comes to
code with python in Linux then it became difficult on the Command Line
Argument. Because python is preinstalled in Linux or we can say it is included
by default in Linux so that makes it important to learn.
1.
To start any python
code: You can
type those command-line arguments individually or write them together in one
scripting with the starting command as pythonin the python interpreter.
Ex:
$ python
>>>x
+ x (where x can be any numerical)
2x(answer to that numerical addition)
If you want to
exist from that session then you can simply type Ctrl+ D.
2.
Print:Print is used to simply print any output from the operations or any
particular sentence.
You
can write multi-line command outside of python interactive console. You are
free to use any other code editor for that as well like Emac, Gedit, Vim, etc.
but vim is the most preferable editor. And after the coding is done you can
save that file with extensionxyz.py.
Ex:
a= x + y;
print a
we have saved
this file with the name addition.py. To run this file in the command
line you can open this as shown below:
3.
Retrieve any .py file:you can retrieve any .py file with the given code below:
$ python
addition.py
X + Y
4.
To execute python
interpreted newly file(.py) or any previously created file (.pl) you can just
write it like./abc.py or with the given name like. /addition1, /addition2.
$ ln
-saddition.py addition1
$. /addition1
Answer
$ln -sf
addition.pl addition1
$. /addition2
Answer
5.
To Fetch Number of Text
files:The main advantage of using the command-line
argument is that we can see all the present files in the same directory as:
$ python
>||>>import
os
>>>os.
listdir (‘.’) // this (.) dot represents the current directory
[‘addition1.txt’,
‘addition2.txt’]
6.
To fetch .py file from
the directory: We can also fetch the .py
file the same way we did for text files.
$ python
>>>
files
[‘addition1.txt’,
‘addition2.txt’]
>>>[files
for file in files if ‘.py’ in file]
[addition.py]
7.
There is another method as
well to fetch all the ‘.txt’ files presented in the current directory.
>>>for
file in files:
… if ‘.txt’ in file:
… print file
…
notes.txt
readme.txt
Python has the indentation
theory in command line argument which tells the python interpreter that what to
use in looping structure as well as in if structure.
Note: Please Enterthe last … (3
dots) after you’re done with the code to letting know to the interpreter.
8.
Delete any file from the
directory: We can also pass the os. system function
in python by using the command line to delete any ''.txt" file from it.
>>> for
file in files:
… if ‘.txt’ in file:
… cmd = ‘rm’ + file
… os. system(cmd)
…
9.
List command: To check whether that file is deleted or not we use the
"ls" command to check all the file lists and can confirm our file
deletion.
>>>os.
system(‘ls’)
addition.py
These are the most used common and basic python commands for the command-line argument from which the best interview questions can be made. Usually, IT company asks python interview questions from this section mostly so be prepare. Not just for the interview but also in real life for safe application building all bigger IT firms use Linux because of its security majors. Our personal opinion as well to use this Linux because it is open-source and there are fewer chances for data theft in Linux.
Comments
Post a Comment