Skip to content

Latest commit

Β 

History

8 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

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.

About

Code demos for python new features including new syntax

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages