第一天

本文深入探讨了Python中不同类型的数据及其操作方法,包括整数、浮点数、复数和Decimal类型的使用与转换,同时介绍了字符串和元组等基本数据结构的操作特性。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >




Python 3.7.0b2 (v3.7.0b2:b0ef5c979b, Feb 28 2018, 02:24:20) [MSC v.1912 64 bit (AMD64)] on win32

Type "copyright", "credits" or "license()" for more information.
>>> 
>>> 
>>> x=10
>>> 


>>> type(x)
<class 'int'>
>>> dir(type)
['__abstractmethods__', '__base__', '__bases__', '__basicsize__', '__call__', '__class__', '__delattr__', '__dict__', '__dictoffset__', '__dir__', '__doc__', '__eq__', '__flags__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__instancecheck__', '__itemsize__', '__le__', '__lt__', '__module__', '__mro__', '__name__', '__ne__', '__new__', '__prepare__', '__qualname__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasscheck__', '__subclasses__', '__subclasshook__', '__text_signature__', '__weakrefoffset__', 'mro']
>>> help
Type help() for interactive help, or help(object) for help about object.
>>> help()


Welcome to Python 3.7's help utility!


If this is your first time using Python, you should definitely check out
the tutorial on the Internet at https://docs.python.org/3.7/tutorial/.


Enter the name of any module, keyword, or topic to get help on writing
Python programs and using Python modules.  To quit this help utility and
return to the interpreter, just type "quit".


To get a list of available modules, keywords, symbols, or topics, type
"modules", "keywords", "symbols", or "topics".  Each module also comes
with a one-line summary of what it does; to list the modules whose name
or summary contain a given string such as "spam", type "modules spam".


help> type
Help on class type in module builtins:


class type(object)
 |  type(object_or_name, bases, dict)
 |  type(object) -> the object's type
 |  type(name, bases, dict) -> a new type
 |  
 |  Methods defined here:
 |  
 |  __call__(self, /, *args, **kwargs)
 |      Call self as a function.
 |  
 |  __delattr__(self, name, /)
 |      Implement delattr(self, name).
 |  
 |  __dir__(self, /)
 |      Specialized __dir__ implementation for types.
 |  
 |  __getattribute__(self, name, /)
 |      Return getattr(self, name).
 |  
 |  __init__(self, /, *args, **kwargs)
 |      Initialize self.  See help(type(self)) for accurate signature.
 |  
 |  __instancecheck__(self, instance, /)
 |      Check if an object is an instance.
 |  
 |  __repr__(self, /)
 |      Return repr(self).
 |  
 |  __setattr__(self, name, value, /)
 |      Implement setattr(self, name, value).
 |  
 |  __sizeof__(self, /)
 |      Return memory consumption of the type object.
 |  
 |  __subclasscheck__(self, subclass, /)
 |      Check if a class is a subclass.
 |  
 |  __subclasses__(self, /)
 |      Return a list of immediate subclasses.
 |  
 |  mro(self, /)
 |      Return a type's method resolution order.
 |  
 |  ----------------------------------------------------------------------
 |  Class methods defined here:
 |  
 |  __prepare__(...)
 |      __prepare__() -> dict
 |      used to create the namespace for the class statement
 |  
 |  ----------------------------------------------------------------------
 |  Static methods defined here:
 |  
 |  __new__(*args, **kwargs)
 |      Create and return a new object.  See help(type) for accurate signature.
 |  
 |  ----------------------------------------------------------------------
 |  Data descriptors defined here:
 |  
 |  __abstractmethods__
 |  
 |  __dict__
 |  
 |  __text_signature__
 |  
 |  ----------------------------------------------------------------------
 |  Data and other attributes defined here:
 |  
 |  __base__ = <class 'object'>
 |      The most base type
 |  
 |  __bases__ = (<class 'object'>,)
 |  
 |  __basicsize__ = 864
 |  
 |  __dictoffset__ = 264
 |  
 |  __flags__ = -2146675712
 |  
 |  __itemsize__ = 40
 |  
 |  __mro__ = (<class 'type'>, <class 'object'>)
 |  
 |  __weakrefoffset__ = 368


help> isinstance
Help on built-in function isinstance in module builtins:


isinstance(obj, class_or_tuple, /)
    Return whether an object is an instance of a class or of a subclass thereof.
    
    A tuple, as in ``isinstance(x, (A, B, ...))``, may be given as the target to
    check against. This is equivalent to ``isinstance(x, A) or isinstance(x, B)
    or ...`` etc.


help> 




You are now leaving help and returning to the Python interpreter.
If you want to ask for help on a particular object directly from the
interpreter, you can type "help(object)".  Executing "help('string')"
has the same effect as typing a particular string at the help> prompt.
>>> isistance(x,int)
Traceback (most recent call last):
  File "<pyshell#8>", line 1, in <module>
    isistance(x,int)
NameError: name 'isistance' is not defined
>>> x
10
>>> isinstance(x,int)
True
>>> isinstance(x,float)
False
>>> x='ok'
>>> x
'ok'
>>> 
>>> 
>>> x=3+4j
>>> x
(3+4j)
>>> type(x)
<class 'complex'>
>>> abs(x)
5.0
>>> help(abs)
Help on built-in function abs in module builtins:


abs(x, /)
    Return the absolute value of the argument.


>>> x.real
3.0
>>> x.imag
4.0
>>> x.


SyntaxError: invalid syntax
>>> 
>>> x.
SyntaxError: invalid syntax
>>> x.conjugate
<built-in method conjugate of complex object at 0x0000025106E15B70>
>>> x
(3+4j)
>>> x.conjugate()
(3-4j)
>>> 1_2_3_4j
1234j
>>> 1.2_3j
1.23j
>>> 1._2
SyntaxError: invalid syntax
>>> from fractions import Fraction
>>> Fraction(3,24)
Fraction(1, 8)
>>> 
>>> from fractions import Fraction Decimal
SyntaxError: invalid syntax
>>> from fractions import Fraction,Decimal
>>> 1/9
0.1111111111111111
>>> 1/3
0.3333333333333333
>>> Decimal(1/3)
Decimal('0.333333333333333314829616256247390992939472198486328125')
>>> dir(Decimal)
['__abs__', '__add__', '__bool__', '__ceil__', '__class__', '__complex__', '__copy__', '__deepcopy__', '__delattr__', '__dir__', '__divmod__', '__doc__', '__eq__', '__float__', '__floor__', '__floordiv__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__int__', '__le__', '__lt__', '__mod__', '__module__', '__mul__', '__ne__', '__neg__', '__new__', '__pos__', '__pow__', '__radd__', '__rdivmod__', '__reduce__', '__reduce_ex__', '__repr__', '__rfloordiv__', '__rmod__', '__rmul__', '__round__', '__rpow__', '__rsub__', '__rtruediv__', '__setattr__', '__sizeof__', '__str__', '__sub__', '__subclasshook__', '__truediv__', '__trunc__', 'adjusted', 'as_integer_ratio', 'as_tuple', 'canonical', 'compare', 'compare_signal', 'compare_total', 'compare_total_mag', 'conjugate', 'copy_abs', 'copy_negate', 'copy_sign', 'exp', 'fma', 'from_float', 'imag', 'is_canonical', 'is_finite', 'is_infinite', 'is_nan', 'is_normal', 'is_qnan', 'is_signed', 'is_snan', 'is_subnormal', 'is_zero', 'ln', 'log10', 'logb', 'logical_and', 'logical_invert', 'logical_or', 'logical_xor', 'max', 'max_mag', 'min', 'min_mag', 'next_minus', 'next_plus', 'next_toward', 'normalize', 'number_class', 'quantize', 'radix', 'real', 'remainder_near', 'rotate', 'same_quantum', 'scaleb', 'shift', 'sqrt', 'to_eng_string', 'to_integral', 'to_integral_exact', 'to_integral_value']
>>> Decimal('3.456442').as_integer_ratio()
(1728221, 500000)
>>> 
>>> help(Decimal)
Help on class Decimal in module decimal:


class Decimal(builtins.object)
 |  Decimal(value='0', context=None)
 |  
 |  Construct a new Decimal object. 'value' can be an integer, string, tuple,
 |  or another Decimal object. If no value is given, return Decimal('0'). The
 |  context does not affect the conversion and is only passed to determine if
 |  the InvalidOperation trap is active.
 |  
 |  Methods defined here:
 |  
 |  __abs__(self, /)
 |      abs(self)
 |  
 |  __add__(self, value, /)
 |      Return self+value.
 |  
 |  __bool__(self, /)
 |      self != 0
 |  
 |  __ceil__(...)
 |  
 |  __complex__(...)
 |  
 |  __copy__(...)
 |  
 |  __deepcopy__(...)
 |  
 |  __divmod__(self, value, /)
 |      Return divmod(self, value).
 |  
 |  __eq__(self, value, /)
 |      Return self==value.
 |  
 |  __float__(self, /)
 |      float(self)
 |  
 |  __floor__(...)
 |  
 |  __floordiv__(self, value, /)
 |      Return self//value.
 |  
 |  __format__(...)
 |      Default object formatter.
 |  
 |  __ge__(self, value, /)
 |      Return self>=value.
 |  
 |  __getattribute__(self, name, /)
 |      Return getattr(self, name).
 |  
 |  __gt__(self, value, /)
 |      Return self>value.
 |  
 |  __hash__(self, /)
 |      Return hash(self).
 |  
 |  __int__(self, /)
 |      int(self)
 |  
 |  __le__(self, value, /)
 |      Return self<=value.
 |  
 |  __lt__(self, value, /)
 |      Return self<value.
 |  
 |  __mod__(self, value, /)
 |      Return self%value.
 |  
 |  __mul__(self, value, /)
 |      Return self*value.
 |  
 |  __ne__(self, value, /)
 |      Return self!=value.
 |  
 |  __neg__(self, /)
 |      -self
 |  
 |  __pos__(self, /)
 |      +self
 |  
 |  __pow__(self, value, mod=None, /)
 |      Return pow(self, value, mod).
 |  
 |  __radd__(self, value, /)
 |      Return value+self.
 |  
 |  __rdivmod__(self, value, /)
 |      Return divmod(value, self).
 |  
 |  __reduce__(...)
 |      Helper for pickle.
 |  
 |  __repr__(self, /)
 |      Return repr(self).
 |  
 |  __rfloordiv__(self, value, /)
 |      Return value//self.
 |  
 |  __rmod__(self, value, /)
 |      Return value%self.
 |  
 |  __rmul__(self, value, /)
 |      Return value*self.
 |  
 |  __round__(...)
 |  
 |  __rpow__(self, value, mod=None, /)
 |      Return pow(value, self, mod).
 |  
 |  __rsub__(self, value, /)
 |      Return value-self.
 |  
 |  __rtruediv__(self, value, /)
 |      Return value/self.
 |  
 |  __sizeof__(...)
 |      Size of object in memory, in bytes.
 |  
 |  __str__(self, /)
 |      Return str(self).
 |  
 |  __sub__(self, value, /)
 |      Return self-value.
 |  
 |  __truediv__(self, value, /)
 |      Return self/value.
 |  
 |  __trunc__(...)
 |  
 |  adjusted(self, /)
 |      Return the adjusted exponent of the number.  Defined as exp + digits - 1.
 |  
 |  as_integer_ratio(self, /)
 |      Decimal.as_integer_ratio() -> (int, int)
 |      
 |      Return a pair of integers, whose ratio is exactly equal to the original
 |      Decimal and with a positive denominator. The ratio is in lowest terms.
 |      Raise OverflowError on infinities and a ValueError on NaNs.
 |  
 |  as_tuple(self, /)
 |      Return a tuple representation of the number.
 |  
 |  canonical(self, /)
 |      Return the canonical encoding of the argument.  Currently, the encoding
 |      of a Decimal instance is always canonical, so this operation returns its
 |      argument unchanged.
 |  
 |  compare(self, /, other, context=None)
 |      Compare self to other.  Return a decimal value:
 |      
 |      a or b is a NaN ==> Decimal('NaN')
 |      a < b           ==> Decimal('-1')
 |      a == b          ==> Decimal('0')
 |      a > b           ==> Decimal('1')
 |  
 |  compare_signal(self, /, other, context=None)
 |      Identical to compare, except that all NaNs signal.
 |  
 |  compare_total(self, /, other, context=None)
 |      Compare two operands using their abstract representation rather than
 |      their numerical value.  Similar to the compare() method, but the result
 |      gives a total ordering on Decimal instances.  Two Decimal instances with
 |      the same numeric value but different representations compare unequal
 |      in this ordering:
 |      
 |          >>> Decimal('12.0').compare_total(Decimal('12'))
 |          Decimal('-1')
 |      
 |      Quiet and signaling NaNs are also included in the total ordering. The result
 |      of this function is Decimal('0') if both operands have the same representation,
 |      Decimal('-1') if the first operand is lower in the total order than the second,
 |      and Decimal('1') if the first operand is higher in the total order than the
 |      second operand. See the specification for details of the total order.
 |      
 |      This operation is unaffected by context and is quiet: no flags are changed
 |      and no rounding is performed. As an exception, the C version may raise
 |      InvalidOperation if the second operand cannot be converted exactly.
 |  
 |  compare_total_mag(self, /, other, context=None)
 |      Compare two operands using their abstract representation rather than their
 |      value as in compare_total(), but ignoring the sign of each operand.
 |      
 |      x.compare_total_mag(y) is equivalent to x.copy_abs().compare_total(y.copy_abs()).
 |      
 |      This operation is unaffected by context and is quiet: no flags are changed
 |      and no rounding is performed. As an exception, the C version may raise
 |      InvalidOperation if the second operand cannot be converted exactly.
 |  
 |  conjugate(self, /)
 |      Return self.
 |  
 |  copy_abs(self, /)
 |      Return the absolute value of the argument.  This operation is unaffected by
 |      context and is quiet: no flags are changed and no rounding is performed.
 |  
 |  copy_negate(self, /)
 |      Return the negation of the argument.  This operation is unaffected by context
 |      and is quiet: no flags are changed and no rounding is performed.
 |  
 |  copy_sign(self, /, other, context=None)
 |      Return a copy of the first operand with the sign set to be the same as the
 |      sign of the second operand. For example:
 |      
 |          >>> Decimal('2.3').copy_sign(Decimal('-1.5'))
 |          Decimal('-2.3')
 |      
 |      This operation is unaffected by context and is quiet: no flags are changed
 |      and no rounding is performed. As an exception, the C version may raise
 |      InvalidOperation if the second operand cannot be converted exactly.
 |  
 |  exp(self, /, context=None)
 |      Return the value of the (natural) exponential function e**x at the given
 |      number.  The function always uses the ROUND_HALF_EVEN mode and the result
 |      is correctly rounded.
 |  
 |  fma(self, /, other, third, context=None)
 |      Fused multiply-add.  Return self*other+third with no rounding of the
 |      intermediate product self*other.
 |      
 |          >>> Decimal(2).fma(3, 5)
 |          Decimal('11')
 |  
 |  is_canonical(self, /)
 |      Return True if the argument is canonical and False otherwise.  Currently,
 |      a Decimal instance is always canonical, so this operation always returns
 |      True.
 |  
 |  is_finite(self, /)
 |      Return True if the argument is a finite number, and False if the argument
 |      is infinite or a NaN.
 |  
 |  is_infinite(self, /)
 |      Return True if the argument is either positive or negative infinity and
 |      False otherwise.
 |  
 |  is_nan(self, /)
 |      Return True if the argument is a (quiet or signaling) NaN and False
 |      otherwise.
 |  
 |  is_normal(self, /, context=None)
 |      Return True if the argument is a normal finite non-zero number with an
 |      adjusted exponent greater than or equal to Emin. Return False if the
 |      argument is zero, subnormal, infinite or a NaN.
 |  
 |  is_qnan(self, /)
 |      Return True if the argument is a quiet NaN, and False otherwise.
 |  
 |  is_signed(self, /)
 |      Return True if the argument has a negative sign and False otherwise.
 |      Note that both zeros and NaNs can carry signs.
 |  
 |  is_snan(self, /)
 |      Return True if the argument is a signaling NaN and False otherwise.
 |  
 |  is_subnormal(self, /, context=None)
 |      Return True if the argument is subnormal, and False otherwise. A number is
 |      subnormal if it is non-zero, finite, and has an adjusted exponent less
 |      than Emin.
 |  
 |  is_zero(self, /)
 |      Return True if the argument is a (positive or negative) zero and False
 |      otherwise.
 |  
 |  ln(self, /, context=None)
 |      Return the natural (base e) logarithm of the operand. The function always
 |      uses the ROUND_HALF_EVEN mode and the result is correctly rounded.
 |  
 |  log10(self, /, context=None)
 |      Return the base ten logarithm of the operand. The function always uses the
 |      ROUND_HALF_EVEN mode and the result is correctly rounded.
 |  
 |  logb(self, /, context=None)
 |      For a non-zero number, return the adjusted exponent of the operand as a
 |      Decimal instance.  If the operand is a zero, then Decimal('-Infinity') is
 |      returned and the DivisionByZero condition is raised. If the operand is
 |      an infinity then Decimal('Infinity') is returned.
 |  
 |  logical_and(self, /, other, context=None)
 |      Return the digit-wise 'and' of the two (logical) operands.
 |  
 |  logical_invert(self, /, context=None)
 |      Return the digit-wise inversion of the (logical) operand.
 |  
 |  logical_or(self, /, other, context=None)
 |      Return the digit-wise 'or' of the two (logical) operands.
 |  
 |  logical_xor(self, /, other, context=None)
 |      Return the digit-wise 'exclusive or' of the two (logical) operands.
 |  
 |  max(self, /, other, context=None)
 |      Maximum of self and other.  If one operand is a quiet NaN and the other is
 |      numeric, the numeric operand is returned.
 |  
 |  max_mag(self, /, other, context=None)
 |      Similar to the max() method, but the comparison is done using the absolute
 |      values of the operands.
 |  
 |  min(self, /, other, context=None)
 |      Minimum of self and other. If one operand is a quiet NaN and the other is
 |      numeric, the numeric operand is returned.
 |  
 |  min_mag(self, /, other, context=None)
 |      Similar to the min() method, but the comparison is done using the absolute
 |      values of the operands.
 |  
 |  next_minus(self, /, context=None)
 |      Return the largest number representable in the given context (or in the
 |      current default context if no context is given) that is smaller than the
 |      given operand.
 |  
 |  next_plus(self, /, context=None)
 |      Return the smallest number representable in the given context (or in the
 |      current default context if no context is given) that is larger than the
 |      given operand.
 |  
 |  next_toward(self, /, other, context=None)
 |      If the two operands are unequal, return the number closest to the first
 |      operand in the direction of the second operand.  If both operands are
 |      numerically equal, return a copy of the first operand with the sign set
 |      to be the same as the sign of the second operand.
 |  
 |  normalize(self, /, context=None)
 |      Normalize the number by stripping the rightmost trailing zeros and
 |      converting any result equal to Decimal('0') to Decimal('0e0').  Used
 |      for producing canonical values for members of an equivalence class.
 |      For example, Decimal('32.100') and Decimal('0.321000e+2') both normalize
 |      to the equivalent value Decimal('32.1').
 |  
 |  number_class(self, /, context=None)
 |      Return a string describing the class of the operand.  The returned value
 |      is one of the following ten strings:
 |      
 |          * '-Infinity', indicating that the operand is negative infinity.
 |          * '-Normal', indicating that the operand is a negative normal number.
 |          * '-Subnormal', indicating that the operand is negative and subnormal.
 |          * '-Zero', indicating that the operand is a negative zero.
 |          * '+Zero', indicating that the operand is a positive zero.
 |          * '+Subnormal', indicating that the operand is positive and subnormal.
 |          * '+Normal', indicating that the operand is a positive normal number.
 |          * '+Infinity', indicating that the operand is positive infinity.
 |          * 'NaN', indicating that the operand is a quiet NaN (Not a Number).
 |          * 'sNaN', indicating that the operand is a signaling NaN.
 |  
 |  quantize(self, /, exp, rounding=None, context=None)
 |      Return a value equal to the first operand after rounding and having the
 |      exponent of the second operand.
 |      
 |          >>> Decimal('1.41421356').quantize(Decimal('1.000'))
 |          Decimal('1.414')
 |      
 |      Unlike other operations, if the length of the coefficient after the quantize
 |      operation would be greater than precision, then an InvalidOperation is signaled.
 |      This guarantees that, unless there is an error condition, the quantized exponent
 |      is always equal to that of the right-hand operand.
 |      
 |      Also unlike other operations, quantize never signals Underflow, even if the
 |      result is subnormal and inexact.
 |      
 |      If the exponent of the second operand is larger than that of the first, then
 |      rounding may be necessary. In this case, the rounding mode is determined by the
 |      rounding argument if given, else by the given context argument; if neither
 |      argument is given, the rounding mode of the current thread's context is used.
 |  
 |  radix(self, /)
 |      Return Decimal(10), the radix (base) in which the Decimal class does
 |      all its arithmetic. Included for compatibility with the specification.
 |  
 |  remainder_near(self, /, other, context=None)
 |      Return the remainder from dividing self by other.  This differs from
 |      self % other in that the sign of the remainder is chosen so as to minimize
 |      its absolute value. More precisely, the return value is self - n * other
 |      where n is the integer nearest to the exact value of self / other, and
 |      if two integers are equally near then the even one is chosen.
 |      
 |      If the result is zero then its sign will be the sign of self.
 |  
 |  rotate(self, /, other, context=None)
 |      Return the result of rotating the digits of the first operand by an amount
 |      specified by the second operand.  The second operand must be an integer in
 |      the range -precision through precision. The absolute value of the second
 |      operand gives the number of places to rotate. If the second operand is
 |      positive then rotation is to the left; otherwise rotation is to the right.
 |      The coefficient of the first operand is padded on the left with zeros to
 |      length precision if necessary. The sign and exponent of the first operand are
 |      unchanged.
 |  
 |  same_quantum(self, /, other, context=None)
 |      Test whether self and other have the same exponent or whether both are NaN.
 |      
 |      This operation is unaffected by context and is quiet: no flags are changed
 |      and no rounding is performed. As an exception, the C version may raise
 |      InvalidOperation if the second operand cannot be converted exactly.
 |  
 |  scaleb(self, /, other, context=None)
 |      Return the first operand with the exponent adjusted the second.  Equivalently,
 |      return the first operand multiplied by 10**other. The second operand must be
 |      an integer.
 |  
 |  shift(self, /, other, context=None)
 |      Return the result of shifting the digits of the first operand by an amount
 |      specified by the second operand.  The second operand must be an integer in
 |      the range -precision through precision. The absolute value of the second
 |      operand gives the number of places to shift. If the second operand is
 |      positive, then the shift is to the left; otherwise the shift is to the
 |      right. Digits shifted into the coefficient are zeros. The sign and exponent
 |      of the first operand are unchanged.
 |  
 |  sqrt(self, /, context=None)
 |      Return the square root of the argument to full precision. The result is
 |      correctly rounded using the ROUND_HALF_EVEN rounding mode.
 |  
 |  to_eng_string(self, /, context=None)
 |      Convert to an engineering-type string.  Engineering notation has an exponent
 |      which is a multiple of 3, so there are up to 3 digits left of the decimal
 |      place. For example, Decimal('123E+1') is converted to Decimal('1.23E+3').
 |      
 |      The value of context.capitals determines whether the exponent sign is lower
 |      or upper case. Otherwise, the context does not affect the operation.
 |  
 |  to_integral(self, /, rounding=None, context=None)
 |      Identical to the to_integral_value() method.  The to_integral() name has been
 |      kept for compatibility with older versions.
 |  
 |  to_integral_exact(self, /, rounding=None, context=None)
 |      Round to the nearest integer, signaling Inexact or Rounded as appropriate if
 |      rounding occurs.  The rounding mode is determined by the rounding parameter
 |      if given, else by the given context. If neither parameter is given, then the
 |      rounding mode of the current default context is used.
 |  
 |  to_integral_value(self, /, rounding=None, context=None)
 |      Round to the nearest integer without signaling Inexact or Rounded.  The
 |      rounding mode is determined by the rounding parameter if given, else by
 |      the given context. If neither parameter is given, then the rounding mode
 |      of the current default context is used.
 |  
 |  ----------------------------------------------------------------------
 |  Class methods defined here:
 |  
 |  from_float(f, /) from builtins.type
 |      Class method that converts a float to a decimal number, exactly.
 |      Since 0.1 is not exactly representable in binary floating point,
 |      Decimal.from_float(0.1) is not the same as Decimal('0.1').
 |      
 |          >>> Decimal.from_float(0.1)
 |          Decimal('0.1000000000000000055511151231257827021181583404541015625')
 |          >>> Decimal.from_float(float('nan'))
 |          Decimal('NaN')
 |          >>> Decimal.from_float(float('inf'))
 |          Decimal('Infinity')
 |          >>> Decimal.from_float(float('-inf'))
 |          Decimal('-Infinity')
 |  
 |  ----------------------------------------------------------------------
 |  Static methods defined here:
 |  
 |  __new__(*args, **kwargs) from builtins.type
 |      Create and return a new object.  See help(type) for accurate signature.
 |  
 |  ----------------------------------------------------------------------
 |  Data descriptors defined here:
 |  
 |  imag
 |  
 |  real


>>> ation
Traceback (most recent call last):
  File "<pyshell#44>", line 1, in <module>
    ation
NameError: name 'ation' is not defined
>>> 
>>> 
>>> x='hello'
>>> x="oh"
>>> x
'oh'
>>> x='''tom said ,"let's go."'''
>>> x
'tom said ,"let\'s go."'
>>> print(x)
tom said ,"let's go."
>>> y=x+"l"
>>> y
'tom said ,"let\'s go."l'
>>> w='ooo' 'dd'
>>> w
'ooodd'
>>> 
>>> 
>>> w
'ooodd'
>>> w.encode()
b'ooodd'
>>> b'o'
b'o'
>>> type(b'o')
<class 'bytes'>
>>> _
<class 'bytes'>
>>> w
'ooodd'
>>> _.encode()
b'ooodd'
>>> _.decode()
'ooodd'
>>> '潘'.encode()
b'\xe6\xbd\x98'
>>> _.decode(gbk)
Traceback (most recent call last):
  File "<pyshell#68>", line 1, in <module>
    _.decode(gbk)
NameError: name 'gbk' is not defined
>>> _
b'\xe6\xbd\x98'
>>> _help
Traceback (most recent call last):
  File "<pyshell#70>", line 1, in <module>
    _help
NameError: name '_help' is not defined
>>> 
>>> x_list=[1,23]
>>> x_list
[1, 23]
>>> t=(3,4)
>>> type(t)
<class 'tuple'>
>>> d={}
>>> type(d)
<class 'dict'>
>>> d={2:'e',4:3}
>>> d
{2: 'e', 4: 3}
>>> d[2]
'e'
>>> 3 in t
True
>>> 
>>> 123%12
3
>>> '%c,%d'%(1,1)
'\x01,1'
>>> 1<2<3
True
>>> 2>3<5
False
>>> 1>6<2
False
>>> 
>>> 'h'>'H'
True
>>> 'hee'>'we'
False
>>> [23,34,5]<[2,3]
False
>>> 'dff'>3
Traceback (most recent call last):
  File "<pyshell#92>", line 1, in <module>
    'dff'>3
TypeError: '>' not supported between instances of 'str' and 'int'
>>> {1,2,3}<{1,3}
False
>>> {3,4}=={e,d}
Traceback (most recent call last):
  File "<pyshell#94>", line 1, in <module>
    {3,4}=={e,d}
NameError: name 'e' is not defined
>>> 
>>> 3 in [2,3]
True
>>> 'ab' in 'adfdsfab'
True
>>> for i in (3,4);
SyntaxError: invalid syntax
>>> for i in (3,4,5):
print(i)


3
4
5
>>> 3 is 3
True
>>> x=[300,300,300]
>>> a=300
>>> x[0] is x[1]
True
>>> x[0] is a
False
>>> a
300
>>> x[0]
300
>>> 
>>> y[300,300,300]
Traceback (most recent call last):
  File "<pyshell#110>", line 1, in <module>
    y[300,300,300]
TypeError: string indices must be integers
>>> y=[300,300,300]
>>> x is y
False
>>> a=1,b=1
SyntaxError: can't assign to literal
>>> a=1;b=1
>>> a is b
True
>>> a
1
>>> 
>>> b
1
>>> v=1
>>> c=1
>>> c is c
True
>>> v='a'
>>> w
'ooodd'
>>> r='a'
>>> v is r
True
>>> 
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值