Python provides the inbuilt function lstrip() to remove all leading spaces from a string.
>>“ Python”.lstrip
Output: Python
Posted Date:- 2021-08-16 05:03:04
There are three types of sequences in Python:
Lists
Tuples
Strings
Example of Lists -
>>l1=[1,2,3]
>>l2=[4,5,6]
>>l1+l2
Output: [1,2,3,4,5,6]
Example of Tuples -
>>t1=(1,2,3)
>>t2=(4,5,6)
>>t1+t2
Output: (1,2,3,4,5,6)
Example of String -
>>s1=“Simpli”
>>s2=“learn”
>>s1+s2
Output: ‘Simplilearn’
Posted Date:- 2021-08-16 05:02:14
The pass statement is used when there's a syntactic but not an operational requirement. For example - The program below prints a string ignoring the spaces.
var="Si mplilea rn"
for i in var:
if i==" ":
pass
else:
print(i,end="")
Here, the pass statement refers to ‘no action required.’
Posted Date:- 2021-08-16 05:01:24
Multithreading usually implies that multiple threads are executed concurrently. The Python Global Interpreter Lock doesn't allow more than one thread to hold the Python interpreter at that particular point of time. So multithreading in python is achieved through context switching. It is quite different from multiprocessing which actually opens up multiple processes across multiple threads.
Posted Date:- 2021-08-16 04:59:53
Deepcopy creates a different object and populates it with the child objects of the original object. Therefore, changes in the original object are not reflected in the copy.
copy.deepcopy() creates a Deep Copy.
Shallow copy creates a different object and populates it with the references of the child objects within the original object. Therefore, changes in the original object are reflected in the copy.
Posted Date:- 2021-08-16 04:59:12
“ len() ” is used to measure the number of elements/items in the List, String, etc.
It will return the number of characters if the object is a string.
Example:
```
a = "Python Language"
b = len(a)
print(b)
```
Output: 15
Posted Date:- 2021-08-16 04:52:53
You can use “+”. Check the below example:
firstName = "Srini"
lastName = "mf"
name = firstName + lastName
Result: Srinimf
Posted Date:- 2021-08-16 04:38:42
Those are “int”, “float”.
Posted Date:- 2021-08-16 04:36:25
Yes, indentation is required in Python. Use tabs instead of single spaces to resolve the silly indentation errors. Indentations make the code easy to read for the developers in all the programming languages but in Python, it is very important to indent the code in a specific order. Mainly the developers use “ tabs ” for indentation in Python programs.
Posted Date:- 2021-08-16 04:34:35
Assert statement is used to evaluate the expression attached. If the expression is false, then python raises an AssertionError Exception.
Posted Date:- 2021-08-16 04:33:16
Those are “FOR” and “WHILE”
Posted Date:- 2021-08-16 04:31:33
“abs ()” is a built-in function that works with integer, float, and complex numbers.
“fabs ()” is defined in the math module which doesn’t work with complex numbers.
Posted Date:- 2021-08-16 04:30:44
The group of individual statements, thereby making a logical block of code are called suites.
Example:
If expression
Suite
Else
Suite
Posted Date:- 2021-08-16 04:29:45
int(x [,base])
Posted Date:- 2021-08-16 04:28:32
currenttime= time.localtime(time.time())
print (“Current time is”, currenttime)
Posted Date:- 2021-08-16 04:27:49
This is one of the string methods which removes leading/trailing white space in the code.
Posted Date:- 2021-08-16 04:26:49
If you give single = , that is called assign.
If you give ==, that is called equal.
Posted Date:- 2021-08-16 04:25:57
To give statements after the IF, the colon is mandatory.
IF sale > 100 :
sale = sale + 20
else :
sale = sale - 20
Posted Date:- 2021-08-16 04:25:17
You need to use input parameter.
newInput = input("abcdefghijk")
print(newInput)
Result:abcdefghijk
Posted Date:- 2021-08-16 04:24:19
You can use “+”. Check the below example:
firstName = "Srini"
lastName = "mf"
name = firstName + lastName
Result: Srinimf
Posted Date:- 2021-08-16 04:20:49
Python supports indentation. Like COBOL, if you remember, there are indentation rules that ‘IF” statement should start from 12th position.
Print ("Hello")
Print ("World")
Posted Date:- 2021-08-16 04:18:11
Basically, Python is an interpreted language. So, the Python code will execute dynamically. Compilation of Python program not required.
Posted Date:- 2021-08-16 04:16:36
Python along with the standard library “Tkinter” is used to create GUI-based applications. Tkinter library supports various widgets that can create and handle events that are widget specific.
Posted Date:- 2021-08-16 04:10:02
Yes. As long as you have the Python environment on your target platform (Linux, Windows, Mac), you can run the same code.
Posted Date:- 2021-08-16 04:07:52
Python has a built-in module called sub-process. You can import this module and either use run() or Popen() function calls to launch a subprocess and get control of its return code.
Posted Date:- 2021-08-16 04:07:03
There are 3 main keywords:
1. Try: Try is the block of a code that is monitored for errors.
2. Except: This block gets executed when an error occurs.
3. Catch: The beauty of the final block is to execute the code after trying for error. This block gets executed irrespective of whether an error occurred or not. Finally block is used to do the required cleanup activities of objects/variables.
Posted Date:- 2021-08-16 04:05:47
Lambda is similar to the inline function in C programming. It returns a function object. It contains only one expression and can accept any number of arguments.
Posted Date:- 2021-08-16 04:03:08
If you add a variable to the <__builtin__> module, it will be accessible as if a global from any other module that includes <__builtin__> — which is all of them, by default.
a.py contains
print foo
b.py contains
import __builtin__
__builtin__.foo = 1
import a
The result is that "1" is printed.
Note: Python 3 introduced the builtins keyword as a replacement for the <__builtin__>
Posted Date:- 2021-08-16 03:59:45
Python has built-in support to parse strings using the Regular expression module.
Perform the following steps to perform the parsing:
1. Import the module and use the functions to find a substring.
2. Replace a part of a string, etc.
Posted Date:- 2021-08-16 03:55:29
Python does not have in-built data structures like arrays, and it does not support arrays. However, you can use List which can store an unlimited number of elements.
Posted Date:- 2021-08-16 03:52:50
The best and easiest tool used to “unit test” is the python standard library, which is also used to test the units/classes. Its features are similar to the other unit testing tools such as JUnit, TestNG.
Posted Date:- 2021-08-16 03:50:07
PIP stands for Python Installer Package, which provides a seamless interface to install the various Python modules. It is a command-line tool that searches for packages over the Internet and installs them without any user interaction.
Posted Date:- 2021-08-16 03:48:51
Yes., Python allows to code in a structured as well as Object-oriented style. It offers excellent flexibility to design and implement the application code depending on the requirements of the application.
Posted Date:- 2021-08-16 03:47:06
Enlisted below are some of the benefits of using Python:
1. Application development is faster and easy.
2. Extensive support of modules for any kind of application development, including data analytics/machine learning/math-intensive applications.
3. Community is always active to resolve user’s queries.
Posted Date:- 2021-08-16 03:46:16
Python is best suited for web server-side application development due to its vast set of features for creating business logic, database interactions, web server hosting, etc.
Posted Date:- 2021-08-16 03:38:10
The above code will produce the following result.
<'aeioubcdfg'>
In Python, while performing string slicing, whenever the indices of both the slices collide, a <+> operator get applied to concatenates them.
Posted Date:- 2021-08-16 03:33:05
No objects in Python have any associated names. So there is no way of getting the one for an object. The assignment is only the means of binding a name to the value. The name then can only refer to access the value. The most we can do is to find the reference name of the object.
Example.
class Test:
def __init__(self, name):
self.cards = []
self.name = name
def __str__(self):
return '{} holds ...'.format(self.name)
obj1 = Test('obj1')
print obj1
obj2 = Test('obj2')
print obj2
Posted Date:- 2021-08-16 03:30:54
In Python, strings are just like lists. And it is easy to convert a string into the list. Simply by passing the string as an argument to the list would result in a string-to-list conversion.
list("I am learning Python.")
Program Output.
Python 2.7.10 (default, Jul 14 2015, 19:46:27)
[GCC 4.8.2] on linux
=> ['I', ' ', 'a', 'm', ' ', 'l', 'e', 'a', 'r', 'n', 'i', 'n', 'g', ' ', 'P', 'y', 't', 'h', 'o', 'n', '.']
Posted Date:- 2021-08-16 03:26:39
We can use Python <split()> function to break a string into substrings based on the defined separator. It returns the list of all words present in the input string.
test = "I am learning Python."
print test.split(" ")
Program Output.
Python 2.7.10 (default, Jul 14 2015, 19:46:27)
[GCC 4.8.2] on linux
['I', 'am', 'learning', 'Python.']
Posted Date:- 2021-08-16 03:23:47
Python has a built-in module called as <random>. It exports a public method <shuffle(<list>)> which can randomize any input sequence.
import random
list = [2, 18, 8, 4]
print "Prior Shuffling - 0", list
random.shuffle(list)
print "After Shuffling - 1", list
random.shuffle(list)
print "After Shuffling - 2", list
Posted Date:- 2021-08-16 03:19:11