Pythonista has Published 22 Articles

How we can create a dictionary from a given tuple in Python?

Pythonista

Pythonista

Updated on 25-Feb-2020 11:14:12

400 Views

We can use zip() function to produce an iterable from two tuple objects, each corresponding to key and value items and then use dict() function to form dictionary object>>> T1=('a', 'b', 'c', 'd') >>> T2=(1, 2, 3, 4) >>> dict((x, y) for x, y in zip(t1, t2))Dictionary comprehension syntax can ... Read More

How to insert a Python tuple in a PostgreSql database?

Pythonista

Pythonista

Updated on 18-Feb-2020 08:04:49

1K+ Views

PostgreSql database is by default installed on port number 5432. Python interface to PostgreSql is provided by installing psycopg2 module. Assuming that test database and employee table with fname, sname, age, gender and salary fields is available.First establish connection and obtain cursor object by following statements in Python script.import psycopg2 ... Read More

How to insert a Python tuple in a MySQL database?

Pythonista

Pythonista

Updated on 18-Feb-2020 08:03:23

2K+ Views

Assuming that MySQL database named as test is present on server and a table named employee is also created. The table has five fields fname, lname, age, gender, and salary.A tuple object containing data of a record is defined ast1=('Mac', 'Mohan', 20, 'M', 2000)To establish interface between MySQL  and Python ... Read More

C++ 'a.out' not recognised as a command

Pythonista

Pythonista

Updated on 10-Feb-2020 10:47:17

5K+ Views

Having entered following command from linux terminal −$ g++ helloworld.cppThe a.out file should be created in the current working directory if the compilation is successful. Check if a.out is created.To execute enter following from command line −$ ./a.outIn most cases, output of your source program is displayed. However, as in ... Read More

How to convert a string to a integer in C

Pythonista

Pythonista

Updated on 27-Jan-2020 12:41:27

581 Views

First extract characters from left bracket '(' using strchr() function.char *name="The Matrix(1999)"; char *ps; ps=strchr(name,'(');Then add each character within brackets () to an char arraychar y[5]=""; int  p; for (p=1;p

What are valid python identifiers?

Pythonista

Pythonista

Updated on 30-Sep-2019 09:00:47

824 Views

An identifier in a Python program is name given to various elements in it, such as keyword, variable, function, class, module, package etc. An identifier should start with either an alphabet (lower or upper case) or underscore (_). More than one alpha-numeric characters or underscore may follow.Keywords are predefined. They ... Read More

compareTo() definition mistake?

Pythonista

Pythonista

Updated on 30-Jul-2019 22:30:22

155 Views

The example works correctly. The compareTo() method is called by a string object and takes another string object as argument. The return value is integer and is difference in Unicode values of characters of respective strings when they are not equal. The value can be -ve, 0 or +ve.

Java is also not pure object-oriented like c++

Pythonista

Pythonista

Updated on 30-Jul-2019 22:30:22

363 Views

the main() method in Java code is itself inside a class. The static keyword lets the main() method which is the entry point of execution without making an object but you need to write a class. In C++, main() is outside the class and writing class it self is not ... Read More

How to write string functions in Java?

Pythonista

Pythonista

Updated on 30-Jul-2019 22:30:22

116 Views

1) take a string from the user and check contains atleast one digit or not:Extract character array from string using toCharArray() method. Run a for loop over each character in array and test if it is a digit by static method isDigit() of character classpublic static boolean chkdigit(String str) { ... Read More

Is there a “not equal” operator in Python?

Pythonista

Pythonista

Updated on 30-Jul-2019 22:30:22

345 Views

In Python 2.x as well as != symbols are defined as 'not equal to' operators. In Python 3, operator is deprecated.

Advertisements