දෝෂ සහිත ක්රමලේඛ නිදොස් කර දක්වා, එම නිදොස් ක්රමලේඛ ක්රියාත්මක කිරීමේදී ලැබෙන ප්රතිදාන මොනවාදැයි සඳහන් කරන්න.
animals=['Dog','Rat','Cat']
animals.sort()
for animal in animals:
print i,animal.strip(),len(animal)
i t=1
animals=['Dog','Rat','Cat']
animals.sort()
for animal in animals:
i=len(animal)
t=animal.strip(),
print (t)
def times(a):
for i in range(1,12):
print a,' x ', i,' = ',a*i
times(5)
def times(a):
for i in range(1,12):
print (a, i,' = ',a*i)
times(5)
===
string -- Common string operations
This module defines some constants useful for checking character classes and some useful string functions. See the module re for string functions based on regular expressions.
The constants defined in this module are:
- ascii_letters
- The concatenation of the ascii_lowercase and ascii_uppercase constants described below. This value is not locale-dependent.
- ascii_lowercase
- The lowercase letters
'abcdefghijklmnopqrstuvwxyz'
. This value is not locale-dependent and will not change.
- ascii_uppercase
- The uppercase letters
'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
. This value is not locale-dependent and will not change.
- digits
- The string
'0123456789'
.
- hexdigits
- The string
'0123456789abcdefABCDEF'
.
- letters
- The concatenation of the strings lowercase and uppercase described below. The specific value is locale-dependent, and will be updated when locale.setlocale() is called.
- lowercase
- A string containing all the characters that are considered lowercase letters. On most systems this is the string
'abcdefghijklmnopqrstuvwxyz'
. Do not change its definition -- the effect on the routines upper() and swapcase() is undefined. The specific value is locale-dependent, and will be updated when locale.setlocale() is called.
- octdigits
- The string
'01234567'
.
- punctuation
- String of ASCII characters which are considered punctuation characters in the "C" locale.
- printable
- String of characters which are considered printable. This is a combination of digits, letters, punctuation, and whitespace.
- uppercase
- A string containing all the characters that are considered uppercase letters. On most systems this is the string
'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
. Do not change its definition -- the effect on the routines lower() and swapcase() is undefined. The specific value is locale-dependent, and will be updated when locale.setlocale() is called.
- whitespace
- A string containing all characters that are considered whitespace. On most systems this includes the characters space, tab, linefeed, return, formfeed, and vertical tab. Do not change its definition -- the effect on the routines strip() and split() is undefined.
-
atof( s) - Deprecated since release 2.0. Use the float() built-in function.Convert a string to a floating point number. The string must have the standard syntax for a floating point literal in Python, optionally preceded by a sign ("+" or "-"). Note that this behaves identical to the built-in function float() when passed a string. Note: When passing in a string, values for NaN and Infinity may be returned, depending on the underlying C library. The specific set of strings accepted which cause these values to be returned depends entirely on the C library and is known to vary.
-
atoi( s[, base]) - Deprecated since release 2.0. Use the int() built-in function.Convert string s to an integer in the given base. The string must consist of one or more digits, optionally preceded by a sign ("+" or "-"). The base defaults to 10. If it is 0, a default base is chosen depending on the leading characters of the string (after stripping the sign): "0x" or "0X" means 16, "0" means 8, anything else means 10. If base is 16, a leading "0x" or "0X" is always accepted, though not required. This behaves identically to the built-in function int() when passed a string. (Also note: for a more flexible interpretation of numeric literals, use the built-in function eval() .)
-
atol( s[, base]) - Deprecated since release 2.0. Use the long() built-in function.Convert string s to a long integer in the given base. The string must consist of one or more digits, optionally preceded by a sign ("+" or "-"). The base argument has the same meaning as for atoi(). A trailing "l" or "L" is not allowed, except if the base is 0. Note that when invoked without base or with base set to 10, this behaves identical to the built-in function long() when passed a string.
-
capitalize( word) - Return a copy of word with only its first character capitalized.
-
capwords( s) - Split the argument into words using split(), capitalize each word using capitalize(), and join the capitalized words using join(). Note that this replaces runs of whitespace characters by a single space, and removes leading and trailing whitespace.
-
expandtabs( s[, tabsize]) - Expand tabs in a string, i.e. replace them by one or more spaces, depending on the current column and the given tab size. The column number is reset to zero after each newline occurring in the string. This doesn't understand other non-printing characters or escape sequences. The tab size defaults to 8.
-
find( s, sub[, start[,end]]) - Return the lowest index in s where the substring sub is found such that sub is wholly contained in
s[start:end]
. Return-1
on failure. Defaults for start and end and interpretation of negative values is the same as for slices.
-
rfind( s, sub[, start[, end]]) - Like find() but find the highest index.
-
index( s, sub[, start[, end]]) - Like find() but raise ValueError when the substring is not found.
-
rindex( s, sub[, start[, end]]) - Like rfind() but raise ValueError when the substring is not found.
-
count( s, sub[, start[, end]]) - Return the number of (non-overlapping) occurrences of substring sub in string
s[start:end]
. Defaults for start and end and interpretation of negative values are the same as for slices.
-
lower( s) - Return a copy of s, but with upper case letters converted to lower case.
-
maketrans( from, to) - Return a translation table suitable for passing to translate() or regex.compile(), that will map each character in from into the character at the same position in to; from and to must have the same length. Warning: Don't use strings derived from lowercase and uppercase as arguments; in some locales, these don't have the same length. For case conversions, always use lower() and upper().
-
split( s[, sep[, maxsplit]]) - Return a list of the words of the string s. If the optional second argument sep is absent or
None
, the words are separated by arbitrary strings of whitespace characters (space, tab, newline, return, formfeed). If the second argument sep is present and notNone
, it specifies a string to be used as the word separator. The returned list will then have one more item than the number of non-overlapping occurrences of the separator in the string. The optional third argument maxsplit defaults to 0. If it is nonzero, at most maxsplit number of splits occur, and the remainder of the string is returned as the final element of the list (thus, the list will have at mostmaxsplit+1
elements).
-
splitfields( s[, sep[, maxsplit]]) - This function behaves identically to split(). (In the past, split() was only used with one argument, while splitfields() was only used with two arguments.)
-
join( words[, sep]) - Concatenate a list or tuple of words with intervening occurrences of sep. The default value for sep is a single space character. It is always true that "string.join(string.split(s, sep), sep)" equals s.
-
joinfields( words[, sep]) - This function behaves identically to join(). (In the past, join() was only used with one argument, while joinfields() was only used with two arguments.) Note that there is no joinfields() method on string objects; use the join() method instead.
-
lstrip( s[, chars]) - Return a copy of the string with leading characters removed. If chars is omitted or
None
, whitespace characters are removed. If given and notNone
, chars must be a string; the characters in the string will be stripped from the beginning of the string this method is called on. Changed in version 2.2.3: The chars parameter was added. The chars parameter cannot be passed in earlier 2.2 versions.
-
rstrip( s[, chars]) - Return a copy of the string with trailing characters removed. If chars is omitted or
None
, whitespace characters are removed. If given and notNone
, chars must be a string; the characters in the string will be stripped from the end of the string this method is called on. Changed in version 2.2.3: The chars parameter was added. The chars parameter cannot be passed in 2.2 versions.
-
strip( s[, chars]) - Return a copy of the string with leading and trailing characters removed. If chars is omitted or
None
, whitespace characters are removed. If given and notNone
, chars must be a string; the characters in the string will be stripped from the both ends of the string this method is called on. Changed in version 2.2.3: The chars parameter was added. The chars parameter cannot be passed in earlier 2.2 versions.
-
swapcase( s) - Return a copy of s, but with lower case letters converted to upper case and vice versa.
-
translate( s, table[, deletechars]) - Delete all characters from s that are in deletechars (if present), and then translate the characters using table, which must be a 256-character string giving the translation for each character value, indexed by its ordinal.
-
upper( s) - Return a copy of s, but with lower case letters converted to upper case.
-
ljust( s, width) -
rjust( s, width) -
center( s, width) - These functions respectively left-justify, right-justify and center a string in a field of given width. They return a string that is at least width characters wide, created by padding the string s with spaces until the given width on the right, left or both sides. The string is never truncated.
-
zfill( s, width) - Pad a numeric string on the left with zero digits until the given width is reached. Strings starting with a sign are handled correctly.
-
replace( str, old, new[, maxsplit]) - Return a copy of string str with all occurrences of substring old replaced by new. If the optional argument maxsplit is given, the first maxsplit occurrences are replaced.
math -- Mathematical functions
This module is always available. It provides access to the mathematical functions defined by the C standard. These functions cannot be used with complex numbers; use the functions of the same name from the cmath module if you require support for complex numbers. The distinction between functions which support complex numbers and those which don't is made since most users do not want to learn quite as much mathematics as required to understand complex numbers. Receiving an exception instead of a complex result allows earlier detection of the unexpected complex number used as a parameter, so that the programmer can determine how and why it was generated in the first place. The following functions are provided by this module. Except when explicitly noted otherwise, all return values are floats: -
acos( x) - Return the arc cosine of x.
-
asin( x) - Return the arc sine of x.
-
atan( x) - Return the arc tangent of x.
-
atan2( y, x) - Return
atan(y / x)
.
-
ceil( x) - Return the ceiling of x as a float.
-
cos( x) - Return the cosine of x.
-
cosh( x) - Return the hyperbolic cosine of x.
-
degrees( x) - Converts angle x from radians to degrees.
-
exp( x) - Return
e**x
.
-
fabs( x) - Return the absolute value of x.
-
floor( x) - Return the floor of x as a float.
-
fmod( x, y) - Return
fmod(x, y)
, as defined by the platform C library. Note that the Python expressionx % y
may not return the same result.
-
frexp( x) - Return the mantissa and exponent of x as the pair
(m, e)
. m is a float and e is an integer such thatx == m * 2**e
. If x is zero, returns(0.0, 0)
, otherwise0.5 <= abs(m) < 1
.
-
hypot( x, y) - Return the Euclidean distance,
sqrt(x*x + y*y)
.
-
ldexp( x, i) - Return
x * (2**i)
.
-
log( x[, base]) - Returns the logarithm of x to the given base. If the base is not specified, returns the natural logarithm of x. Changed in version 2.3: base argument added.
-
log10( x) - Return the base-10 logarithm of x.
-
modf( x) - Return the fractional and integer parts of x. Both results carry the sign of x. The integer part is returned as a float.
-
pow( x, y) - Return
x**y
.
-
radians( x) - Converts angle x from degrees to radians.
-
sin( x) - Return the sine of x.
-
sinh( x) - Return the hyperbolic sine of x.
-
sqrt( x) - Return the square root of x.
-
tan( x) - Return the tangent of x.
-
tanh( x) - Return the hyperbolic tangent of x.
The module also defines two mathematical constants:
- pi
- The mathematical constant pi.
- e
- The mathematical constant e.
No comments:
Post a Comment