0% found this document useful (0 votes)
39 views

Argument Variable (Argv Module or Library) : From Import From Import

This document provides information about escape sequences, string formatting, file I/O functions in Python, and basic functions like len() and return. It defines escape sequences like \n and \t, string formatters like %s and %d, file modes like 'r' and 'w', common file functions like open(), read(), and close(), the len() function which returns the length of a string, and the return statement. It also briefly explains functions in Python using def and function arguments.

Uploaded by

belgandor
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
39 views

Argument Variable (Argv Module or Library) : From Import From Import

This document provides information about escape sequences, string formatting, file I/O functions in Python, and basic functions like len() and return. It defines escape sequences like \n and \t, string formatters like %s and %d, file modes like 'r' and 'w', common file functions like open(), read(), and close(), the len() function which returns the length of a string, and the return statement. It also briefly explains functions in Python using def and function arguments.

Uploaded by

belgandor
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 2

ESCAPEWHAT IT DOES.

\\Backslash (\)\'Single-quote (')\"Double-quote (")\aASCII bell


(BEL)\bASCII backspace (BS)\fASCII formfeed (FF)\nASCII linefeed (LF)\N{name}Character
named name in the Unicode database (Unicode only)\rCarriage Return (CR)\tHorizontal Tab
(TAB)\uxxxxCharacter with 16-bit hex value xxxx (Unicode only)\UxxxxxxxxCharacter with 32-bit
hex value xxxxxxxx (Unicode only)\vASCII vertical tab (VT)\oooCharacter with octal value
ooo\xhhCharacter with hex value hh

print - prints a sentence


We put a , (comma) at the end of each print line. This is soprint doesn't end the line with a
newline character and go to the next line.
# - pound - a comment, used to describe something within the code
+ plus
- minus
/ slash
* asterisk
% percent
< less-than
> greater-than
<= less-than-equal
>= greater-than-equal

\n newlines

"hababababa" - format string


%s - formatter used for displaying to users
%r - formatter Use the %r for debugging, since it displays the "raw" data of the variable
%d - formatter used for displaying to users
raw_input()
y = raw_input("Name? ") - prompt

from sys import argv – imports argv from sys


argv - argument variable (argv = module or library)

from sys import argv

script, first, second, third = argv

open() habababa.open(variable)

read() txt.read(variable)

close()

close -- Closes the file. Like File->Save.. in your editor.


·read -- Reads the contents of the file. You can assign the result to a variable.
·readline -- Reads just one line of a text file.
·truncate -- Empties the file. Watch out if you care about the file.
·write('stuff') -- Writes "stuff" to the file.

What does 'w' mean?


It's really just a string with a character in it for the kind of mode for the file. If you
use 'w' then you're saying "open this file in 'write' mode," thus the 'w' character.
There's also 'r' for "read,"'a' for append, and modifiers on these
What modifiers to the file modes can I use?
The most important one to know for now is the + modifier, so you can do 'w+', 'r+',
and 'a+'. This will open the file in both read and write mode, and depending on the
character use position the file in different ways.

indata = open(from_file).read()

What does the len() function do?


It gets the length of the string that you pass to it then returns that as a number. Play
with it.

Functions do three things:


1They name pieces of code the way variables name strings and numbers.
2They take arguments the way your scripts take argv.
3Using 1 and 2 they let you make your own "mini-scripts" or "tiny
commands."
def - function

What is +=?
You know how in English I can rewrite "it is" as "it's"? Or I can rewrite "you are" as
"you're"? In English this is called a contraction, and this is kind of like a contraction
for the two operations =and +. That means x = x + y is the same as x += y.

return

You might also like