Found 26504 Articles for Server Side Programming

How to print in same line in Python?

pawandeep
Updated on 22-Aug-2023 02:09:21

123K+ Views

The print() method in Python automatically prints in the next line each time. The print() method by default takes the pointer to the next line.Example Live Demofor i in range(5):    print(i)Output0 1 2 3 4Modify print() method to print on the same lineThe print method takes an extra parameter end=" " to keep the pointer on the same line.The end parameter can take certain values such as a space or some sign in the double quotes to separate the elements printed in the same line.Syntaxprint("..." , end=" ")Print on same line with space between each elementThe end=” “ is used ... Read More

How to declare a variable in Python?

pawandeep
Updated on 23-Aug-2023 14:16:00

68K+ Views

In Python, we need not declare a variable with some specific data type.Python has no command for declaring a variable. A variable is created when some value is assigned to it. The value assigned to a variable determines the data type of that variable.Thus, declaring a variable in Python is very simple.Just name the variableAssign the required value to itThe data type of the variable will be automatically determined from the value assigned, we need not define it explicitly.Declare an integer variableTo declare an integer variable −Name the variableAssign an integer value to itExample Live Demox=2 print(x) print(type(x))This is how you ... Read More

How to create a dictionary in Python?

pawandeep
Updated on 10-Mar-2021 14:05:15

2K+ Views

A Dictionary in Python is a type of data structure.It consists of a collection of key-value pairs. Each key in the dictionary is unique. Each unique key in the dictionary is associated to its value. Thus, Dictionary holds key : value pairs.We will be discussing how to create a dictionary in Python.Create a DictionaryA dictionary in Python can be created by placing various key: value pairs inside curly braces .The key:value pairs are separated from each other using commas(, ). The values in the dictionary can be of any datatype and can be duplicated. However, the keys in the dictionary ... Read More

How to convert int to string in Python?

pawandeep
Updated on 10-Mar-2021 14:03:57

1K+ Views

Type conversion is at times needed when the user wants to convert one data type into another data type according to requirement.Python has in-built function str() to convert an integer to a string. We will be discussing various other methods in addition to this to convert int into string in Python.Using str()This is the most commonly used method to convert int into string in Python.The str() takes integer variable as a parameter and converts it into a string.Syntaxstr(integer variable)Example Live Demonum=2 print("Datatype before conversion", type(num)) num=str(num) print(num) print("Datatype after conversion", type(num))OutputDatatype before conversion 2 Datatype after conversion The type() function ... Read More

How to compare two lists in Python?

pawandeep
Updated on 23-Aug-2023 13:50:34

71K+ Views

The list in python is a collection of similar items. We may at times need to compare data items in the two lists to perform certain operations. We will discuss certain methods to compare two lists in python.Using list.sort() and == operatorThe list.sort() method sorts the two lists and the == operator compares the two lists item by item which means they have equal data items at equal positions. This checks if the list contains equal data item values but it does not take into account the order of elements in the list. This means that the list [1, 2, ... Read More

How to convert list to string in Python?

pawandeep
Updated on 10-Mar-2021 13:59:46

2K+ Views

There may be some situations, where we need to convert a list into a string. We will discuss different methods to do the same.IterationIterate through the list and append the elements to the string to convert list into a string. We will use for-in loop to iterate through the list elements.Example Live Demolist1=["Welcome", "To", "Tutorials", "Point"] string1="" for i in list1:    string1=string1+i string2="" for i in list1:    string2=string2+i+" " print(string1) print(string2)OutputWelcomeToTutorialsPoint Welcome To Tutorials PointUsing .join() methodThe list will be passed as a parameter inside the join method.Example Live Demolist1=["Welcome", "To", "Tutorials", "Point"] string1="" print(string1.join(list1)) string2=" " print(string2.join(list1))OutputWelcomeToTutorialsPoint Welcome To ... Read More

How to run Python Program?

pawandeep
Updated on 10-Mar-2021 13:55:17

9K+ Views

After writing the code, we need to run the code to execute and obtain the output. On running the program, we can check whether the code is written is correct and produces the desired output.Running a python program is quite an easy task.Run on IDLETo run a python program on IDLE, follow the given steps −Write the python code and save it.To run the program, go to Run > Run Module or simply click F5.Run on Command LineThe python script file is saved with ‘.py’ extension. After saving the python script, we can run it from the Command Line. In ... Read More

How to reverse a string in Python program?

pawandeep
Updated on 10-Mar-2021 13:54:29

1K+ Views

Python has no in-built function to reverse a string. Thus, we need to implement our own logic to reverse a string.We will reverse a string using different methods.Using FOR LoopThe idea behind this method is to use a reverse loop starting from the last index of the string to the 0th index. At each iteration, we will be adding characters of the string to hold the reversed string at the end of the iterations.Let’s look on the general procedure we will be following −a:=new stringloop from last index of string to 0th index and decrement by 1 a=a+character at the ... Read More

How to install Python in Windows?

pawandeep
Updated on 26-Feb-2024 11:05:03

207K+ Views

Python is a widely used high-level programming language. To write and execute code in python, we first need to install Python on our system.Installing Python on Windows takes a series of few easy steps.Step 1 − Select Version of Python to InstallPython has various versions available with differences between the syntax and working of different versions of the language. We need to choose the version which we want to use or need. There are different versions of Python 2 and Python 3 available.Step 2 − Download Python Executable InstallerOn the web browser, in the official site of python (www.python.org), move ... Read More

How to detect and track the motion of eyeball in OpenCV using C++?

Ginni
Updated on 10-Mar-2021 09:16:37

530 Views

Here, we will learn how to detect and track the motion of eyeball in OpenCV.The following program demonstrates to detect the eyeball and track the location.Example#include #include #include #include #include #include using namespace cv; using namespace std; Vec3f eyeBallDetection(Mat& eye, vector& circles) {    vectorsums(circles.size(), 0);    for (int y = 0; y < eye.rows; y++) {       uchar* data = eye.ptr(y);       for (int x = 0; x < eye.cols; x++) {          int pixel_value = static_cast(*data);          for (int i = 0; i < circles.size(); i++) {   ... Read More

Advertisements