saba_tavdgiridze's blog

By saba_tavdgiridze, 10 years ago, In English

Hello! It's my first useful and solid blog at all( well, i think so )

Recently i was searching some information about useful data-structures, built-in functions and other interesting shortcuts in python. python is vary popular language among programmers, so I came up with an idea to write there brief review of this tasks(these may not be "very" interesting for "redcoders" I think :D )

(You maybe think that you can look up everything that you need in Python documantaion, but believe me, there things are little hard and messy to understand ;) )

Contents:

  • I/O (input/output)
  • ...
  • ...
  • ...
  • ...
  • ...
  • ...
  • ...

I/O(input/output)

Allmost every program has three components : input, processing and output.Python has a built-in function, called raw_input(), that's used to get input from the user.

  • raw_input() function :

The raw_input() function gets a string from the user. The normal way it gets this is from the keyboard(stdin) .Let's see some examples :

print "Please ,enter your name :"
name=raw_input()
print "Hello",name

There is a shortcut for printing prompt messages. The raw_input() function can print the message for you, so you don’t have to use a "print" statement:

name=raw_input("Please ,enter your name :")
print "Hello",name

Because raw_input() get string from stdin you can use int() or float() for your needs ,to get number( and not string ) :

number=int(raw_input("Please ,enter your number :"))
print "You entered",number

There is another way to get numbers as input. Python has a function called input() that gives you a number directly, so you don’t have to use int() or float() to convert it. However, there are some reasons not to use input(). One of them is that the input() function is removed from future versions of Python (versions 3.0 and later). There is only raw_input() and They renamed raw_input() as input().

will be continued ...

sorry for my bad English... ( Any remarks will be appreciated )

  • Vote: I like it
  • +3
  • Vote: I do not like it

»
10 years ago, # |
  Vote: I like it +4 Vote: I do not like it

Somewhat related: in vexorian's blog, you can find his review of an experiment — writing TopCoder SRMs 611-620 using Python exclusively. The story begins here.