Giter VIP home page Giter VIP logo

python-cool-features's Introduction

python-cool-features

中文说明

This project is an implementation of a deck of cards in Python. It is a standard 52 card deck, with 4 suits, and 13 cards in each suit. The cards can be shuffled, and drawn from the deck.

Features

The project demonstrates many Python features introduced from Python 3.6 to 3.12:

  1. PEP 634: Structural Pattern Matching: match case
  2. PEP 572: Assignment Expressions: walrus operator
  3. New annotations, such as: str | int, list[str] | None, etc.
  4. PEP 616: String methods to remove prefixes and suffixes: str.removeprefix(), str.removesuffix()
  5. f-string: f"{variable=}" to print variable name and value, f"{variable!r}" to print variable name and repr(variable), f"{variable:<8}" to align left, f"{variable:>8}" to align right, f"{variable:^8}" to align center
  6. dataclasses: dataclass, field, ClassVar, _post_init_
  7. str.center(width, fill_char)
  8. dict new features
  9. etc.

Classes

The project includes the following classes:

  • SUIT: An enumeration representing the four suits of a deck of cards.
  • Card: A class representing a playing card, with a rank and a suit.
  • Deck: A class representing a deck of cards.
  • FrenchDeck: A subclass of Deck that generates a standard 52 card deck.

Usage

To use the deck of cards, create an instance of FrenchDeck, shuffle it, and draw cards:

deck = FrenchDeck()
deck.shuffle()
hand: list[Card] = deck.make_hand(num_cards=5)
┌─────────┐┌─────────┐┌─────────┐┌─────────┐┌─────────┐
│ 7       ││ 8       ││ J       ││ Q       ││ K       │
│ ♣       ││ ♣       ││ ♠       ││ ♠       ││ ♣       │
│         ││         ││         ││         ││         │
│       ♣ ││       ♣ ││       ♠ ││       ♠ ││       ♣ │
│       7 ││       8 ││       J ││       Q ││       K │
└─────────┘└─────────┘└─────────┘└─────────┘└─────────┘

Requirements

This script requires Python 3.12 or later.

python-cool-features's People

Contributors

albertmenglongli avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.