Java | Python |
---|---|
statically typed | dynamically typed |
In Java, all variable names (along with their types) must be explicitly declared. Attempting to assign an object of the wrong type to a variable name triggers a type exception. That’s what it means to say that Java is a statically typed language. |
In Python, you never declare anything. An assignment statement binds a name to an object, and the object can be of any type. If a name is assigned to an object of one type, it may later be assigned to an object of a different type. That’s what it means to say that Python is a dynamically typed language. |
Java | Python |
---|---|
|
|
|
|
Data in tuple cant be change after created
print "list2[1:5]: ", list2[1:5]
What is the output?
x = ['ab', 'cd'] for i in x: x.append(i.upper()) print(x)
What is the output ?
a) [‘AB’, ‘CD’]
b) [‘ab’, ‘cd’, ‘AB’, ‘CD’]
c) [‘ab’, ‘cd’]
d) none of the mentioned
x = ['ab', 'cd'] for i in x: i.upper() print(x)
What is the output ?
a) [‘AB’, ‘CD’]
b) [‘ab’, ‘cd’, ‘AB’, ‘CD’]
c) [‘ab’, ‘cd’]
d) none of the mentioned
>>> str1 = 'hello'
>>> str1[-1:]
What is the output ?
a) olleh
b) hello
c) h
d) o