Python  

Getting Started

Python is a great object-oriented, interpreted, and interactive programming language. It is often compared (favorably of course  ) to Lisp, Tcl, Perl, Ruby, C#, Visual Basic, Visual Fox Pro, Scheme or Java... and it's much more fun.

Code Diff

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


 

 
 

 

The syntax

Hello World & comment

Mathematics

Quote & newline

List

List ..

Tuple

Data in tuple cant be change after created

Dictionaries

Conditional

for Loop

for Loop ..

while Loop

function

input from user

String

Question

Question 1

list2 = [1, 2, 3, 4, 5, 6, 7 ];

print "list2[1:5]: ", list2[1:5]

What is the output?

Question 2

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

Question 3

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

Question 4

  1. >>> str1 = 'hello'
  2. >>> str1[-1:]

What is the output ?

a) olleh
b) hello
c) h
d) o

python getting started

By Syafiq bin abdul rahman