Skip to content

Instantly share code, notes, and snippets.

@Paddy3118
Last active August 12, 2018 08:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Paddy3118/3fe7cd50e803710e4627dff3edee1cab to your computer and use it in GitHub Desktop.
Save Paddy3118/3fe7cd50e803710e4627dff3edee1cab to your computer and use it in GitHub Desktop.
Investigate adjacent string literals
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "markdown",
"metadata": {
"toc": "true"
},
"source": [
"# Table of Contents\n",
" <p><div class=\"lev1 toc-item\"><a href=\"#More-f-strings\" data-toc-modified-id=\"More-f-strings-1\"><span class=\"toc-item-num\">1&nbsp;&nbsp;</span>More f strings</a></div><div class=\"lev2 toc-item\"><a href=\"#Lets-try-slicing-and-dicing\" data-toc-modified-id=\"Lets-try-slicing-and-dicing-1.1\"><span class=\"toc-item-num\">1.1&nbsp;&nbsp;</span>Lets try slicing and dicing</a></div><div class=\"lev2 toc-item\"><a href=\"#Now-mix-f-and-non-f-string-literals\" data-toc-modified-id=\"Now-mix-f-and-non-f-string-literals-1.2\"><span class=\"toc-item-num\">1.2&nbsp;&nbsp;</span>Now mix f and non-f string literals</a></div><div class=\"lev1 toc-item\"><a href=\"#Conclusion\" data-toc-modified-id=\"Conclusion-2\"><span class=\"toc-item-num\">2&nbsp;&nbsp;</span>Conclusion</a></div>"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# More f strings\n",
"No, literally more f-strings, as in what happens when you have a mixture of f, and normal string literals?"
]
},
{
"cell_type": "code",
"execution_count": 16,
"metadata": {},
"outputs": [],
"source": [
"g, d, p = 'Go', 'deh', 'Paddy!'"
]
},
{
"cell_type": "code",
"execution_count": 17,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Go deh Paddy!\n"
]
}
],
"source": [
"print(f'{g} {d} {p}')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Lets try slicing and dicing"
]
},
{
"cell_type": "code",
"execution_count": 18,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Go deh Paddy!\n"
]
}
],
"source": [
"print(f'{g} ' f'{d} ' f'{p}')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Now mix f and non-f string literals"
]
},
{
"cell_type": "code",
"execution_count": 19,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"{g} deh Paddy!\n"
]
}
],
"source": [
"print('{g} ' f'{d} ' f'{p}')"
]
},
{
"cell_type": "code",
"execution_count": 20,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Go {d} Paddy!\n"
]
}
],
"source": [
"print(f'{g} ' '{d} ' f'{p}')"
]
},
{
"cell_type": "code",
"execution_count": 21,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Go deh {p}\n"
]
}
],
"source": [
"print(f'{g} ' f'{d} ' '{p}')"
]
},
{
"cell_type": "code",
"execution_count": 22,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Go {d} {p}\n"
]
}
],
"source": [
"print(f'{g} ' '{d} ' '{p}')"
]
},
{
"cell_type": "code",
"execution_count": 23,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"{g} deh {p}\n"
]
}
],
"source": [
"print('{g} ' f'{d} ' '{p}')"
]
},
{
"cell_type": "code",
"execution_count": 24,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"{g} {d} Paddy!\n"
]
}
],
"source": [
"print('{g} ' '{d} ' f'{p}')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Conclusion\n",
"It seems as if adjacent string literals are first interpreted according to their kind and only then concatenated."
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python [conda root]",
"language": "python",
"name": "conda-root-py"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.6"
},
"nav_menu": {},
"toc": {
"navigate_menu": true,
"number_sections": true,
"sideBar": true,
"threshold": 6,
"toc_cell": true,
"toc_section_display": "block",
"toc_window_display": false
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment