Python Tuple Initialization with one value – Quick and Easy Thumb Rule:

To create a tuple with one element, you need to do this:

>>> my_tuple = (1,)                  # Note the trailing comma after the value 1
>>> type(my_tuple)
<type ‘tuple’>

But if you do this

>>> my_tuple = (1)
>>> type(my_tuple)
<type ‘int’>

you don’t get a tuple. I thought that just putting a value inside ( )
would make a tuple. Apparently that is not the case. I hate ugly code
so it would be clean if Python would convert anything put into ( ) to
be a tuple, even if just one value was put in use comma after the value, For example:  “my_tuple = (1,) “.

Difference between raw_input, input and eval in python

In Python 2, raw_input() returns a string

But whereas input() tries to run the input as a Python expression. Since getting a string was almost always what you wanted, Python 3 does that with input() .

Note: input() is now raw_input() in python 3.x versions.

eval in python

Eval evaluates expressions. eval() , as the name suggests, evaluates the passed argument.

Example: Try eval(input()) and type “1+1” – this should print 2 .

Difference between expression and statement in python

Expression: Any value is an expression

Expressions are nothing but values, except they can have operations like addition or subtraction. eval evaluates the string as if it were a python expression.


3 + 5
map(lambda x: x*x, range(10))
[a.x for a in some_iterable]
yield 7

Statement: Anything that does something is a statement. Any assignment to a variable or function call is a statement.


if x: do_y()
a = 7