Dino Geek, try to help you

What are the differences between Python 2 and Python 3?


Python 2 and Python 3 have several differences, some of the notable ones include:

1. Print Function: In Python 2, “print” is treated as a statement rather than a function. You could print something like this: print “Hello, World!”. But in Python 3, “print” is a function, and you have to print something like this: print(“Hello, World!”).

1. Division Operation: In Python 2, the division of two integers returns an integer, while in Python 3, the division of two integers has a float result. For example, in Python 2, 3/2 = 1. In contrast, in Python 3, 3/2 = 1.5.

1. Unicode: Python 2 ascii strings are used by default, but in Python 3 strings are stored as Unicode by default.

1. Syntax: The syntax of Python 3 is simpler and easily understandable whereas Python 2 has more complicated syntax.

1. Range function: The range() function in Python 3 returns a range object that generates numbers on demand. In contrast, Python 2’s range() creates a list in memory right away, which is less efficient for large ranges.

1. Error Handling: In Python 3, errors can be handled by using: “except Exception as e”. This is not allowed in Python 2.

1. End of Life: Python 2 has reached its end of life in 2020, meaning it will not receive any further updates and is not recommended for use in new projects. Python 3 continues to be actively developed and updated.

1. Libraries: Many popular libraries have stopped supporting Python 2 after it reached end of life. New libraries and tools are often only available for Python 3.

1. Syntax to represent octal values: In Python 2 we represent octal number like 027. But in Python 3 we represent octal number like 0o27.

1. Input Function: In Python 2, raw_input() is used to take input from users, but in Python 3, raw_input() is renamed to input().


Simply generate articles to optimize your SEO
Simply generate articles to optimize your SEO





DinoGeek offers simple articles on complex technologies

Would you like to be quoted in this article? It's very simple, contact us at dino@eiki.fr

CSS | NodeJS | DNS | DMARC | MAPI | NNTP | htaccess | PHP | HTTPS | Drupal | WEB3 | LLM | Wordpress | TLD | Domain name | IMAP | TCP | NFT | MariaDB | FTP | Zigbee | NMAP | SNMP | SEO | E-Mail | LXC | HTTP | MangoDB | SFTP | RAG | SSH | HTML | ChatGPT API | OSPF | JavaScript | Docker | OpenVZ | ChatGPT | VPS | ZIMBRA | SPF | UDP | Joomla | IPV6 | BGP | Django | Reactjs | DKIM | VMWare | RSYNC | Python | TFTP | Webdav | FAAS | Apache | IPV4 | LDAP | POP3 | SMTP

| Whispers of love (API) | Déclaration d'Amour |






Legal Notice / General Conditions of Use