第1页
Python Python Software Foundation PSF print print Eclipse PyCharm print ("content") IPO Input Process Output while(True): a=1 infinite loops val if val elif else inital-print inital-print IDE input() print() int() float() bool() str int weight_lbs =
第2页
input('Weight (lbs): ') weight_kg = int(weight_lbs) * 0.45 print(weight_kg) course = 'Python for Beginners' another = course[:] print(another) first = 'John' last = 'Smith' message = first + ' [' + last + '] is a coder' msg = f'{first} [{last}] is a
第3页
coder' print(msg) print(len(course)) print(len(course)) print(course.upper()) print(course.lower()) print(course) len() course.upper() course.lower() course.title() course.find() course.replace() '...' in course Number-theoretic and representation fu
第4页
nctions math.ceil(x) Return the ceiling of x, the smallest integer greater than or equal to x. If x is not a float, delegates to x.__ceil__(), which should return an Integral value. math.comb(n, k) Return the number of ways to choose k items from n i
第5页
tems without repetition and without order. Evaluates to n! / (k! * (n - k)!) when k <= n and evaluates to zero when k > n. Also called the binomial coefficient because it is equivalent to the coefficient of k-th term in polynomial expansion of the ex
第6页
pression (1 + x) ** n. Raises TypeError if either of the arguments are not integers. Raises ValueError if either of the arguments are negative. New in version 3.8. math.copysign(x, y) Return a float with the magnitude (absolute value) of x but the si
第7页
gn of y. On platforms that support signed zeros, copysign(1.0, -0.0) returns -1.0. math.fabs(x) Return the absolute value of x. math.factorial(x) Return x factorial as an integer. Raises ValueError if x is not integral or is negative. math.floor(x) R
第8页
eturn the floor of x, the largest integer less than or equal to x. If x is not a float, delegates to x.__floor__(), which should return an Integral value. math.fmod(x, y) Return fmod(x, y), as defined by the platform C library. Note that the Python e
第9页
xpression x % y may not return the same result. The intent of the C standard is that fmod(x, y) be exactly (mathematically; to infinite precision) equal to x - n*y for some integer n such that the result has the same sign as x and magnitude less than
第10页
abs(y). Python's x % y returns a result with the sign of y instead, and may not be exactly computable for float arguments. For example, fmod(-1e-100, 1e100) is -1e-100, but the result of Python's -1e-100 % 1e100 is 1e100-1e-100, which cannot be repr
第11页
esented exactly as a float, and rounds to the surprising 1e100. For this reason, function fmod() is generally preferred when working with floats, while Python's x % y is preferred when working with integers. math.frexp(x) Return the mantissa and expo
第12页
nent of x as the pair (m, e). m is a float and e is an integer such that x == m * 2**e exactly. If x is zero, returns (0.0, 0), otherwise 0.5 <= abs(m) < 1. This is used to "pick apart" the internal representation of a float in a portable way. math.f
第13页
sum(iterable) Return an accurate floating point sum of values in the iterable. Avoids loss of precision by tracking multiple intermediate partial sums: >>>