Wednesday 10 May 2017

Python

Reading Keyboard Input

raw_input([prompt]) function reads one line from standard input and returns it as a string

#!/usr/bin/python

str = raw_input("Enter your input: ");
print "Received input is : ", str
Enter your input: Hello Python
Received input is :  Hello Python 

Standard Data Types

Python has standard data types -

  • Numbers(int, long, float)
  • String....str.strlen(),
  • List(list.insert(), list.remove()...etc)
  • Dictionary(dict.key(), dict.values()). 

 Data Type Conversion

int(x [,base])
Converts x to an integer. base specifies the base if x is a string.
str(x)
Converts object x to a string representation.
list(s)
Converts s to a list.

 The from...import Statement

Python's from statement lets you import specific attributes from a module into the current namespace.

from fib import fibonacci

 

 

No comments:

Post a Comment