learning Python- types

Programs are composed of modules

Modules contain statements

Statements contain expression

Expression create and process objects


Everything we process is a kind of object.


1. numbers

2. strings

3. lists

4. dictionaries

5. tuples

6. files

7. sets

8. other core types: booleans,types,none

9.program unit type:functions,modules,classes

10. implementation-related types: compiled code,stack trackback


Python is dynamically typed, a model that keeps track of types for you automatically instead of requiring declaration code, but it is also strongly typed,a constraint that means you can perform on an object only operations that are valid for its type.

sets: &:intersection 

          |:union

          - difference

          set comprehension  {n ** 2 for n in [1, 2, 3, 4]}

Even less mathematically inclined programmers often find sets useful for common tasks
such as filtering out duplicates, isolating differences, and performing order-neutral
equality tests without sorting—in lists, strings, and all other iterable objects:


Sets also support in membership tests, though all other collection types in Python do
too:

'p' in set('spam'), 'p' in 'spam', 'ham' in ['eggs', 'spam', 'ham']

(True,True,True)


fraction(rational numbers with both a numerator and a denominator) 

from fractions import Fraction # Fractions: numerator+denominator
>>> f = Fraction(2, 3)
>>> f + 1
Fraction(5, 3)
>>> f + Fraction(1, 2)
Fraction(7, 6)

decimal(fixed-precision)

import decimal                 # Decimals: fixed precision
>>> d = decimal.Decimal('3.141')
>>> d + 1
Decimal('4.141')

User-Defined Type:class


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值