請問python中int的意思?
python小白,剛寫一個,但是必須加上int,請問int是什麼意思?
a=int(input(please enter number))if a&>=25:print(6666)
else: print(5555)
因為input接收的值會轉化為字元型,所以int的作用是強制類型轉化即轉化為整型數據。
學會使用help
Python 3.5.2 (v3.5.2:4def2a2901a5, Jun 25 2016, 22:18:55) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
&>&>&> help(int)
Help on class int in module builtins:
class int(object)
| int(x=0) -&> integer
| int(x, base=10) -&> integer
|
| Convert a number or string to an integer, or return 0 if no arguments
| are given. If x is a number, return x.__int__(). For floating point
| numbers, this truncates towards zero.
|
| If x is not a number or if base is given, then x must be a string,
| bytes, or bytearray instance representing an integer literal in the
| given base. The literal can be preceded by + or - and be surrounded
| by whitespace. The base defaults to 10. Valid bases are 0 and 2-36.
| Base 0 means to interpret the base from the string as an integer literal.
| &>&>&> int(0b100, base=0)
| 4
|
| Methods defined here:
|
| __abs__(self, /)
| abs(self)
|
| __add__(self, value, /)
| Return self+value.
|
| __and__(self, value, /)
| Return selfvalue.
|
| __bool__(self, /)
| self != 0
|
| __ceil__(...)
| Ceiling of an Integral returns itself.
|
| __divmod__(self, value, /)
| Return divmod(self, value).
|
| __eq__(self, value, /)
| Return self==value.
|
| __float__(self, /)
| float(self)
|
| __floor__(...)
| Flooring an Integral returns itself.
|
| __floordiv__(self, value, /)
| Return self//value.
|
| __format__(...)
| default object formatter
|
| __ge__(self, value, /)
| Return self&>=value.
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __getnewargs__(...)
|
| __gt__(self, value, /)
| Return self&>value.
|
| __hash__(self, /)
| Return hash(self).
|
| __index__(self, /)
| Return self converted to an integer, if self is suitable for use as an index into a list.
|
| __int__(self, /)
| int(self)
|
| __invert__(self, /)
| ~self
|
| __le__(self, value, /)
| Return self&<=value.
|
| __lshift__(self, value, /)
| Return self&<&
|
| __rshift__(self, value, /)
| Return self&>&>value.
|
| __rsub__(self, value, /)
| Return value-self.
|
| __rtruediv__(self, value, /)
| Return value/self.
|
| __rxor__(self, value, /)
| Return value^self.
|
| __sizeof__(...)
| Returns size in memory, in bytes
|
| __str__(self, /)
| Return str(self).
|
| __sub__(self, value, /)
| Return self-value.
|
| __truediv__(self, value, /)
| Return self/value.
|
| __trunc__(...)
| Truncating an Integral returns itself.
|
| __xor__(self, value, /)
| Return self^value.
|
| bit_length(...)
| int.bit_length() -&> int
|
| Number of bits necessary to represent self in binary.
| &>&>&> bin(37)
| 0b100101
| &>&>&> (37).bit_length()
| 6
|
| conjugate(...)
| Returns self, the complex conjugate of any int.
|
| from_bytes(...) from builtins.type
| int.from_bytes(bytes, byteorder, *, signed=False) -&> int
|
| Return the integer represented by the given array of bytes.
|
| The bytes argument must be a bytes-like object (e.g. bytes or bytearray).
|
| The byteorder argument determines the byte order used to represent the
| integer. If byteorder is big, the most significant byte is at the
| beginning of the byte array. If byteorder is little, the most
| significant byte is at the end of the byte array. To request the native
| byte order of the host system, use `sys.byteorder as the byte order value.
|
| The signed keyword-only argument indicates whether twos complement is
| used to represent the integer.
|
| to_bytes(...)
| int.to_bytes(length, byteorder, *, signed=False) -&> bytes
|
| Return an array of bytes representing an integer.
|
| The integer is represented using length bytes. An OverflowError is
| raised if the integer is not representable with the given number of
| bytes.
|
| The byteorder argument determines the byte order used to represent the
| integer. If byteorder is big, the most significant byte is at the
| beginning of the byte array. If byteorder is little, the most
| significant byte is at the end of the byte array. To request the native
| byte order of the host system, use `sys.byteorder as the byte order value.
|
| The signed keyword-only argument determines whether twos complement is
| used to represent the integer. If signed is False and a negative integer
| is given, an OverflowError is raised.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| denominator
| the denominator of a rational number in lowest terms
|
| imag
| the imaginary part of a complex number
|
| numerator
| the numerator of a rational number in lowest terms
|
| real
| the real part of a complex number
善於使用help(),google,stack-overflow以及最重要的http://python.org
https://docs.python.org/3/library/functions.html#int
把你輸入的數據強制轉化為整數 如果你輸入了小數 它會取前面整數那部分 如果你輸入了其他的比如字母什麼的 系統會報錯
這樣處理之後 這個數據就可以拿來當數字用了,加減乘除比大小之類的
另外這東西也多用於一些一定要用整數的地方,比如表示年齡啊,數量啊之類的
help()的話 雖然裡面的英語都很基礎 但我是看不懂的?(ˉ?ˉ?) 初學者可以多用谷歌,必應 盡量別用百度
最後 謝邀 謝邀 謝邀
a變數中存儲著input中的內容,也就是一個str,而且要和25進行比較,如果你不用int()進行轉化,那你就拿著一個字元串和一個整數進行比較,會產生錯誤。
輸入的值是字元串而不是數字,int將其轉換成數字。
推薦閱讀:
※為什麼學完慕課網上python的課程,感覺還是一無所知?
※你做過哪些有趣的基於網路爬蟲的應用?
※使用爬蟲如果不是用來為機器學習或數據挖掘收集數據,還能做什麼有趣的事情呢……?
※如何能找到失散多年的朋友?
※如何判斷瀏覽器post的是form data還是json data?