\documentclass[a4paper,11pt]{article}
\usepackage[polish]{babel}
\usepackage[utf8]{inputenc} 
\usepackage[T1]{fontenc}
\usepackage{fourier}
\usepackage[scaled=0.85]{beramono}
\usepackage{listings}
\usepackage{xcolor}
\usepackage{geometry}
\lstloadlanguages{Python}

\geometry{width=126mm}



\begin{document}

\lstset{language=Python,
  basicstyle=\ttfamily\small,
  identifierstyle=\underline,
  commentstyle=\itshape\color{gray},
  stringstyle=\color{black!70},
  numberstyle=\scriptsize,
  numbers=left,
  xleftmargin=5mm,
  xrightmargin=5mm,
  frame=tb,
  rulecolor=\color{gray},
  framerule=2pt, 
}
\begin{lstlisting}
x = 'LaTeX'
print(x)
y = x[2:]                # y = 'TeX'
print(y)
print('I love ' + x)
\end{lstlisting}

\end{document}