Open In App

How to Print a Deck of Cards in Python

Last Updated : 23 Jul, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

This article teaches how to print a deck of cards using Python. The most commonly used deck is a standard 52-card French-suited pack, which is:

  • Widely used in English-speaking nations.
  • The only regularly available pattern in countries like the UK and the US.
  • Composed of 4 suits and 13 ranks, making a total of 52 cards (4 × 13 = 52).

Suits and Ranks

  • Suits: Club (♣), Diamond (♦), Heart (♥), Spade (♠)
  • Ranks: A, 2, 3, 4, 5, 6, 7, 8, 9, 10, J, Q, K

1. Print a Deck of Cards using Python

  • Create a list of 4 suits.
  • Create a list of 13 ranks.
  • Iterate over each rank.
  • For every rank, iterate over all suits.
  • Print the combination.

Code:

Python
Suits = ['CLUB', 'DIAMOND',
         'Heart', 'SPADE']
Ranks = ['A', '2', '3', '4',
         '5', '6', '7', '8',
         '9', '10', 'J', 'Q', 'K']

for rank in Ranks:

    for suit in Suits:
        print(f'{rank} of {suit}'.ljust(16), end='')
    print()

Output:

A of CLUB A of DIAMOND A of Heart A of SPADE
2 of CLUB 2 of DIAMOND 2 of Heart 2 of SPADE
3 of CLUB 3 of DIAMOND 3 of Heart 3 of SPADE
4 of CLUB 4 of DIAMOND 4 of Heart 4 of SPADE
5 of CLUB 5 of DIAMOND 5 of Heart 5 of SPADE
6 of CLUB 6 of DIAMOND 6 of Heart 6 of SPADE
7 of CLUB 7 of DIAMOND 7 of Heart 7 of SPADE
8 of CLUB 8 of DIAMOND 8 of Heart 8 of SPADE
9 of CLUB 9 of DIAMOND 9 of Heart 9 of SPADE
10 of CLUB 10 of DIAMOND 10 of Heart 10 of SPADE
J of CLUB J of DIAMOND J of Heart J of SPADE
Q of CLUB Q of DIAMOND Q of Heart Q of SPADE
K of CLUB K of DIAMOND K of Heart K of SPADE

Explanation:

  • Suits and Ranks lists define the components of a deck.
  • Outer loop iterates over each rank.
  • Inner loop pairs each rank with every suit.
  • f'{rank} of {suit}'.ljust(16) formats and aligns the output.
  • print() at the end starts a new line after each row.

2. Print a Deck with Unicode Symbols

  • Use Unicode symbols for suits.
  • Iterate over ranks and suits as before.
  • Print formatted output.

Code:

Python
Suits = ["\u2663", "\u2665", "\u2666", "\u2660"] 

Ranks = ['A', '2', '3', '4', '5', '6', '7', '8', '9', '10', 'J', 'Q', 'K'] 

for rank in Ranks: 
    for suit in Suits: 
        print(f'{rank} of {suit}'.ljust(10), end='') 
    print()

Output:

A of ♣ A of ♥ A of ♦ A of ♠
2 of ♣ 2 of ♥ 2 of ♦ 2 of ♠
3 of ♣ 3 of ♥ 3 of ♦ 3 of ♠
4 of ♣ 4 of ♥ 4 of ♦ 4 of ♠
5 of ♣ 5 of ♥ 5 of ♦ 5 of ♠
6 of ♣ 6 of ♥ 6 of ♦ 6 of ♠
7 of ♣ 7 of ♥ 7 of ♦ 7 of ♠
8 of ♣ 8 of ♥ 8 of ♦ 8 of ♠
9 of ♣ 9 of ♥ 9 of ♦ 9 of ♠
10 of ♣ 10 of ♥ 10 of ♦ 10 of ♠
J of ♣ J of ♥ J of ♦ J of ♠
Q of ♣ Q of ♥ Q of ♦ Q of ♠
K of ♣ K of ♥ K of ♦ K of ♠

Explanation:

  • Unicode characters (\u2663 etc.) represent the suit symbols ♣ ♥ ♦ ♠.
  • Ranks and loops remain the same as in the previous example.
  • The output is compact and visually resembles real cards.

3. Shuffle a Deck of Cards

  • Use itertools.product() to create all combinations.
  • Use random.shuffle() to randomize the deck.
  • Print shuffled deck in chunks of 4 for readability.

Code:

Python
from itertools import product 
from random import shuffle 

Suits = ["\u2663", "\u2665", "\u2666", "\u2660"] 
Ranks = ['A', '2', '3', '4', '5', '6', '7', '8', '9', '10', 'J', 'Q', 'K'] 

deck = list(product(Ranks, Suits)) 
shuffle(deck) 

for i in range(0, len(deck), 4): 
    print("{} {} {} {}".format(
        deck[i][0] + deck[i][1],
        deck[i+1][0] + deck[i+1][1],
        deck[i+2][0] + deck[i+2][1],
        deck[i+3][0] + deck[i+3][1]
    ))

Output:

2♠ 5♥ 2♣ 10♠
K♥ 7♣ Q♦ 8♠
K♦ 7♥ 6♠ 6♣
J♣ 10♥ 9♦ 5♦
10♣ 8♥ 6♥ J♦
A♠ K♠ J♠ 7♠
K♣ Q♥ Q♣ J♥
A♥ 4♣ 3♥ 7♦
8♦ 8♣ 4♠ 3♦
6♦ 2♦ A♣ 10♦
9♣ 2♥ 5♣ Q♠
A♦ 9♥ 3♣ 5♠
3♠ 4♥ 9♠ 4♦

Explanation:

  • product(Ranks, Suits) generates all 52 combinations of rank and suit.
  • shuffle(deck) randomizes the order of the deck.
  • deck[i][0] + deck[i][1] joins rank and suit symbol for display.
  • Loop prints 4 cards per line for better readability.

Related article: Unicode characters


Practice Tags :

Similar Reads