Minor edits to data-file.org.
--- a/data-types.org Tue Apr 20 13:39:41 2010 +0530
+++ b/data-types.org Wed Apr 21 14:28:38 2010 +0530
@@ -10,38 +10,37 @@
In this tutorial we shall look at data types available in Python and
how to perform simple Input and Output operations.
- for dealing with 'Numbers' we have: int, float, complex
- 'Strings' are there for handling Text content.
- For conditional statements 'Booleans' are supported.
+ for 'Numbers' we have: int, float, complex datatypes
+ for Text content we have strings.
+ For conditional statements, 'Booleans'.
- Lets start by covering one by one, firstly 'numbers'
- All integer numbers irrespective of how big they are, are of 'int'
+ Lets get started by opening IPython interpreter.
+ Lets start with 'numbers'
+ All integers irrespective of how big they are, are of 'int'
data type
- Lets get started by opening IPython interpreter. Now we will create
- some variables say:
- a = 13
- print a
+ Now we will create a variable, say
+ x = 13
+ print x
To check the data type of any variable Python provides 'type' function
- type(a)
+ type(x)
- b = 999999999999
- print b
+ y = 999999999999
+ print y
Floating point numbers comes under 'float'
p = 3.141592
type(p)
- Python by default provides support to complex numbers.
+ Python by default provides support for complex numbers.
c = 3+4j
c is a complex number. 'j' is used to specify the imaginary part.
type(c)
Python also provides basic functions for their manipulations like
abs(c) will return the absolute value of c(sqrt(a^2 + b^2))
- c.imag returns imaginary part of the variable
- and similarly c.real gives real part.
+ c.imag returns imaginary part and c.real gives the real part.
- Next we will look at Boolean data types:
+ Next we will look at Boolean datatype:
Its a primitive datatype having one of two values: True or False.
t = True
print t
@@ -99,19 +98,20 @@
returns true if initial of the string is same
similarly there is endswith
a.endswith('ING')
- a.upper() returns a string will all letters capitalized.
+ a.upper() returns a string with all letters capitalized.
and a.lower() returns a string with all smaller case letters.
As we have seen earlier use of split function, it returns the list after
splitting the string, so
a.split()
will give list with three elements.
- Opposite to this function, we also have 'join' function.
+ we also have 'join' function, which does the opposite of what
+ split does.
''.join(['a','b','c']) will return a joined string of the list we pass
to it. Since join is performed on '' that is empty string we get 'abc'
if we do something like
'-'.join(['a','b','c'])
- Thus we come to the end of this tutorial on introduction of Data types in
+ we come to the end of this tutorial on introduction of Data types in
Python. In this tutorial we have learnt what are supported data types,
supported operations and performing simple IO operations in Python.