0% found this document useful (0 votes)
10 views8 pages

Chuong1 Python

The document provides an overview of Python's built-in functions and formatting types, including examples of how to use them. It also covers mathematical functions for rounding and formatting numbers, as well as user input syntax. Additionally, it includes examples of various numeric types and how to handle long expressions in Python.

Uploaded by

23021213
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views8 pages

Chuong1 Python

The document provides an overview of Python's built-in functions and formatting types, including examples of how to use them. It also covers mathematical functions for rounding and formatting numbers, as well as user input syntax. Additionally, it includes examples of various numeric types and how to handle long expressions in Python.

Uploaded by

23021213
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

Python

https://docs.python.org/3/library/functions.html
Built-in Functions
Built-in Functions
A E L R
abs() enumerate() len() range()
aiter() eval() list() repr()
all() exec() locals() reversed()
anext() round()
any() F M
ascii() filter() map() S
float() max() set()
B format() memoryview() setattr()
bin() frozenset() min() slice()
bool() sorted()
breakpoint() G N staticmethod()
bytearray() getattr() next() str()
bytes() globals() sum()
O super()
Built-in Functions
C H object()
callable() hasattr() oct() T
chr() hash() open() tuple()
classmethod() help() ord() type()
compile() hex()
complex() P V
I pow() vars()
D id() print()
delattr() input() property() Z
dict() int() zip()
dir() isinstance()
divmod() issubclass() _
iter() __import__()

https://www.w3schools.com/python/python_string_formatting.asp

Here is a list of all the formatting types.

Formatting Types

:< Try it Left aligns the result (within the available space)

:> Try it Right aligns the result (within the available space)
:^ Try it Center aligns the result (within the available space)

:= Try it Places the sign to the left most position

:+ Try it Use a plus sign to indicate if the result is positive or negative

:- Try it Use a minus sign for negative values only

: Try it Use a space to insert an extra space before positive numbers (and a minus sign before negative numbers)

:, Try it Use a comma as a thousand separator

:_ Try it Use a underscore as a thousand separator

:b Try it Binary format

:c Converts the value into the corresponding Unicode character

:d Try it Decimal format

:e Try it Scientific format, with a lower case e

:E Try it Scientific format, with an upper case E

:f Try it Fix point number format

:F Try it Fix point number format, in uppercase format (show inf and nan as INF and NAN)

:g General format

:G General format (using a upper case E for scientific notations)

:o Try it Octal format

:x Try it Hex format, lower case


:X Try it Hex format, upper case

:n Number format

:% Try it Percentage format

math.ceil() Rounds a number up to the nearest integer

math.floor() Rounds a number down to the nearest integer

math.trunc() Returns the truncated integer parts of a number

math.remainder() Returns the closest value that can make numerator completely divisible by the denominator

math.fmod() (%) Returns the remainder of x/y


Định dạng (Output): A = a  a. (có ký tự symbol)
1 1 11
   4  1 0 5
 2 n  3 !  2 n  3  7 ! 7 (1e-5)
Quy tròn: A  1,
2345
  1,235
  1,24

A a a

import math # print_characters.py


print(ord('a')) # stt trong bang mã ascii
print(chr(177)) # return symbol
print('Gia tri so e = ', math.e)
delta = 0.0001
# Quy tròn đến số nào tùy ý.
print('e=
','{:.5f}'.format(math.e),chr(177),'{:.4f}'.format(delta))
# x = round(5.76543, 3) # sử dụng trong tính toán. round(number, digits)
(Input): https://www.w3schools.com/python/python_user_input.asp
Syntax: input(prompt): (built-in functions)
prompt :A String, representing a default message before the
input
Text Type: str

Numeric Types: int, float, complex

Sequence Types: list, tuple, range

Mapping Type: dict

Set Types: set, frozenset

Boolean Type: bool

Binary Types: bytes, bytearray, memoryview

None Type: NoneType


Numeric Types: int, float, complex
Ví dụ:
x = input('Enter your name:')
print('Hello, ' + x)
int_x = int(input('Nhap so nguyen x = '))
float_x = float(input('Nhap so thuc x = '))
print(float_x*2)
Nếu biểu thức dài cần xuống dòng có 2 cách
+ Dùng dấu ngoặc
+ dùng dấu \
Ví dụ:
a = 1+ 2
a = 1+\
2
A = (1+
2)

You might also like